Migrate and freeze goals creation (#2833)
* Full migration (to be submitted separately) * Do not remove `Goal.domain` just yet * Do not make Goal.site not nullable just yet * Temporarily disable goal creation * Rephrase error message * Add down migrationpull/2838/head r2023.04.10-99
parent
df67f7c378
commit
3cb089eab4
@ -0,0 +1,28 @@
|
||||
defmodule :"Elixir.Plausible.Repo.Migrations.Associate-goals-with-sites" do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
alter table(:goals) do
|
||||
add :site_id, :integer, null: true
|
||||
end
|
||||
|
||||
execute """
|
||||
DELETE FROM goals g WHERE NOT EXISTS (
|
||||
SELECT 1 FROM sites s
|
||||
WHERE s.domain = g.domain
|
||||
)
|
||||
"""
|
||||
|
||||
execute """
|
||||
UPDATE goals g SET site_id = (
|
||||
SELECT s.id FROM sites s WHERE s.domain = g.domain
|
||||
)
|
||||
"""
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:goals) do
|
||||
remove :site_id
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue