[migration] Data fix: rewrite goals for which `event_name` and `page_path` both exist (#3357)
* Rewrite goals for which both event_name and page_path exist. This might've happened due to the old form only hiding form fields from the viewport, allowing to submit both values in certain cases when switching tabs. The tabs behaviour has been changed as of #3293 but no proper constraints existed. * Add new check constraint to the goals schema * Use NOT VALID option for adding the CHECK constraint * Skip wrapping migration in a single transactionpull/3359/head r2023.09.18-192
parent
8c077513ac
commit
a5bac43981
@ -0,0 +1,29 @@
|
||||
defmodule Plausible.Repo.Migrations.FixBrokenGoals do
|
||||
use Ecto.Migration
|
||||
|
||||
@disable_ddl_transaction true
|
||||
@disable_migration_lock true
|
||||
|
||||
def up do
|
||||
execute("""
|
||||
UPDATE goals SET page_path = NULL WHERE page_path IS NOT NULL AND event_name IS NOT NULL
|
||||
""")
|
||||
|
||||
execute("""
|
||||
ALTER TABLE goals
|
||||
ADD CONSTRAINT check_event_name_or_page_path
|
||||
CHECK (
|
||||
(event_name IS NOT NULL AND page_path IS NULL) OR
|
||||
(event_name IS NULL AND page_path IS NOT NULL)
|
||||
)
|
||||
NOT VALID;
|
||||
""")
|
||||
end
|
||||
|
||||
def down do
|
||||
execute("""
|
||||
ALTER TABLE goals
|
||||
DROP CONSTRAINT check_event_name_or_page_path;
|
||||
""")
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue