mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 09:01:40 +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!")
|
||||
end
|
||||
|
||||
def pending_migrations do
|
||||
prepare()
|
||||
IO.puts("Pending migrations")
|
||||
IO.puts("")
|
||||
Enum.each(repos(), &list_pending_migrations_for/1)
|
||||
end
|
||||
|
||||
def seed do
|
||||
prepare()
|
||||
# Run seed script
|
||||
@ -92,6 +99,28 @@ defmodule Plausible.Release do
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
|
||||
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
|
||||
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
|
||||
""")
|
||||
|
||||
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
|
||||
@ -23,7 +28,7 @@ defmodule Plausible.Repo.Migrations.FixBrokenGoals do
|
||||
def down do
|
||||
execute("""
|
||||
ALTER TABLE goals
|
||||
DROP CONSTRAINT check_event_name_or_page_path;
|
||||
DROP CONSTRAINT IF EXISTS check_event_name_or_page_path;
|
||||
""")
|
||||
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