mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 17:11:36 +03:00
Make FixBrokenGoals migration idempotent (#3405)
* 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
This commit is contained in:
parent
21297b666f
commit
dec193e904
@ -25,6 +25,13 @@ defmodule Plausible.Release do
|
|||||||
IO.puts("Migrations successful!")
|
IO.puts("Migrations successful!")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pending_migrations do
|
||||||
|
prepare()
|
||||||
|
IO.puts("Pending migrations")
|
||||||
|
IO.puts("")
|
||||||
|
Enum.each(repos(), &list_pending_migrations_for/1)
|
||||||
|
end
|
||||||
|
|
||||||
def seed do
|
def seed do
|
||||||
prepare()
|
prepare()
|
||||||
# Run seed script
|
# Run seed script
|
||||||
@ -92,6 +99,28 @@ defmodule Plausible.Release do
|
|||||||
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp list_pending_migrations_for(repo) do
|
||||||
|
IO.puts("Listing pending migrations for #{repo}")
|
||||||
|
IO.puts("")
|
||||||
|
|
||||||
|
migration_directory = Ecto.Migrator.migrations_path(repo)
|
||||||
|
|
||||||
|
pending =
|
||||||
|
repo
|
||||||
|
|> Ecto.Migrator.migrations([migration_directory])
|
||||||
|
|> Enum.filter(fn {status, _version, _migration} -> status == :down end)
|
||||||
|
|
||||||
|
if pending == [] do
|
||||||
|
IO.puts("No pending migrations")
|
||||||
|
else
|
||||||
|
Enum.each(pending, fn {_, version, migration} ->
|
||||||
|
IO.puts("* #{version}_#{migration}")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
IO.puts("")
|
||||||
|
end
|
||||||
|
|
||||||
defp ensure_repo_created(repo) do
|
defp ensure_repo_created(repo) do
|
||||||
IO.puts("create #{inspect(repo)} database if it doesn't exist")
|
IO.puts("create #{inspect(repo)} database if it doesn't exist")
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ defmodule Plausible.Repo.Migrations.FixBrokenGoals do
|
|||||||
UPDATE goals SET page_path = NULL WHERE page_path IS NOT NULL AND event_name IS NOT NULL
|
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("""
|
execute("""
|
||||||
ALTER TABLE goals
|
ALTER TABLE goals
|
||||||
ADD CONSTRAINT check_event_name_or_page_path
|
ADD CONSTRAINT check_event_name_or_page_path
|
||||||
@ -23,7 +28,7 @@ defmodule Plausible.Repo.Migrations.FixBrokenGoals do
|
|||||||
def down do
|
def down do
|
||||||
execute("""
|
execute("""
|
||||||
ALTER TABLE goals
|
ALTER TABLE goals
|
||||||
DROP CONSTRAINT check_event_name_or_page_path;
|
DROP CONSTRAINT IF EXISTS check_event_name_or_page_path;
|
||||||
""")
|
""")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
6
rel/overlays/pending-migrations.sh
Executable file
6
rel/overlays/pending-migrations.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# lists pending migrations
|
||||||
|
|
||||||
|
BIN_DIR=$(dirname "$0")
|
||||||
|
|
||||||
|
"${BIN_DIR}"/bin/plausible eval Plausible.Release.pending_migrations
|
Loading…
Reference in New Issue
Block a user