Skip to content

Commit

Permalink
add 'no pending migration'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Aug 31, 2024
1 parent 981093d commit e6d1988
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/plausible_release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ defmodule Plausible.Release do

def pending_streaks(repos \\ repos()) do
prepare()
IO.puts("Collecting pending migrations..\n")
IO.puts("Collecting pending migrations..")

pending = all_pending_migrations(repos)
streaks = migration_streaks(pending)

print_migration_streaks(streaks, pending)
if pending == [] do
IO.puts("No pending migrations!")
else
streaks = migration_streaks(pending)
print_migration_streaks(streaks, pending)
end
end

defp print_migration_streaks([{repo, up_to_version} | streaks], pending) do
Expand All @@ -133,12 +137,10 @@ defmodule Plausible.Release do
end)

IO.puts(
"#{inspect(repo)} [#{Path.relative_to_cwd(Ecto.Migrator.migrations_path(repo))}] streak up to version #{up_to_version}:"
"\n#{inspect(repo)} [#{Path.relative_to_cwd(Ecto.Migrator.migrations_path(repo))}] streak up to version #{up_to_version}:"
)

Enum.each(streak, fn {_repo, version, name} -> IO.puts(" * #{version}_#{name}") end)
IO.puts("")

print_migration_streaks(streaks, pending)
end

Expand Down
24 changes: 24 additions & 0 deletions test/plausible/release_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ defmodule Plausible.ReleaseTest do
:ok
end

defp last_migration(repo) do
{:ok, {_status, version, name}, _started} =
Ecto.Migrator.with_repo(repo, fn repo ->
repo
|> Ecto.Migrator.migrations()
|> List.last()
end)

"#{version}_#{name}"
end

defp fake_migrate(repo, up_to_migration) do
{up_to_version, _name} = Integer.parse(up_to_migration)

Expand Down Expand Up @@ -220,6 +231,19 @@ defmodule Plausible.ReleaseTest do
Plausible.ReleaseTest.PostgreSQL [_build/test/lib/plausible/priv/repo/migrations] streak up to version \
""" <> _future = pending_streaks

fake_migrate(PostgreSQL, last_migration(PostgreSQL))
fake_migrate(ClickHouse, last_migration(ClickHouse))

no_streaks = capture_io(fn -> Release.pending_streaks([PostgreSQL, ClickHouse]) end)

assert no_streaks == """
Loading plausible..
Starting dependencies..
Starting repos..
Collecting pending migrations..
No pending migrations!
"""
end
end
end

0 comments on commit e6d1988

Please sign in to comment.