mirror of
https://github.com/plausible/analytics.git
synced 2024-12-02 07:38:47 +03:00
dec193e904
* Make FixBrokenGoals migration idempotent The migration in question was renamed in order to fix order of executing migrations when run from the ground up (via https://github.com/plausible/analytics/pull/3378). As a side effect, it's executed again on databases that had it applied earlier, with a different timestamp prefix. As this migration is safe to run multiple times, it was modified to make forward migration work gracefully when constraint already exists. * Add `pending-migrations.sh` release script
35 lines
764 B
Elixir
35 lines
764 B
Elixir
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
|
|
DROP CONSTRAINT IF EXISTS check_event_name_or_page_path;
|
|
""")
|
|
|
|
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 IF EXISTS check_event_name_or_page_path;
|
|
""")
|
|
end
|
|
end
|