mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
[Housekeeping] Refactor settings model (#165)
* [WIP] renamed current settings module and tables to have backup suffix * Created new settings table, schema, and context * Migrated from old settings module to new one * Removed settings backup modules * Added some tests and docs
This commit is contained in:
parent
d9053fff0c
commit
24875eaeac
12 changed files with 171 additions and 183 deletions
|
|
@ -0,0 +1,7 @@
|
|||
defmodule Pinchflat.Repo.Migrations.RenameSettingsTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
rename table(:settings), to: table(:settings_backup)
|
||||
end
|
||||
end
|
||||
29
priv/repo/migrations/20240404174144_create_new_settings.exs
Normal file
29
priv/repo/migrations/20240404174144_create_new_settings.exs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
defmodule Pinchflat.Repo.Migrations.CreateNewSettings do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
create table(:settings) do
|
||||
add :onboarding, :boolean, default: true, null: false
|
||||
add :pro_enabled, :boolean, default: false, null: false
|
||||
add :yt_dlp_version, :string
|
||||
end
|
||||
|
||||
# Make an initial record because this will be the only one ever inserted
|
||||
execute "INSERT INTO settings (onboarding, pro_enabled, yt_dlp_version) VALUES (true, false, NULL)"
|
||||
|
||||
# Set the value of onboarding to the previous version set in `settings_backup`
|
||||
execute """
|
||||
UPDATE settings
|
||||
SET onboarding = COALESCE((SELECT value = 'true' FROM settings_backup WHERE name = 'onboarding'), true)
|
||||
"""
|
||||
|
||||
execute """
|
||||
UPDATE settings
|
||||
SET pro_enabled = COALESCE((SELECT value = 'true' FROM settings_backup WHERE name = 'pro_enabled'), false)
|
||||
"""
|
||||
end
|
||||
|
||||
def down do
|
||||
drop table(:settings)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue