Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/phoenix_ecto/check_repo_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Phoenix.Ecto.CheckRepoStatus do

* `:otp_app` - name of the application which the repos are fetched from
* `:migration_paths` - a function that accepts a repo and returns a migration directory, or a list of migration directories, that is used to check for pending migrations
* `:migration_lock` - the locking strategy used by the Ecto Adapter when checking for pending migrations. Set to `false` to disable migration locks.
* `:migration_lock` - the locking strategy used by the Ecto Adapter when checking for pending migrations. Defaults to `false`. Set to `true` to enable migration locks.
* `:prefix` - the prefix used to check for pending migrations.
* `:skip_table_creation` - Ecto will not try to create the `schema_migrations` table automatically. This is useful if you are connecting as a DB user without create permissions
"""
Expand Down Expand Up @@ -67,7 +67,11 @@ defmodule Phoenix.Ecto.CheckRepoStatus do
end)

true = is_function(migrations_fun, 3)
migration_opts = Keyword.take(opts, @migration_opts)

migration_opts =
opts
|> Keyword.take(@migration_opts)
|> Keyword.put_new(:migration_lock, false)

try do
repo
Expand Down
19 changes: 16 additions & 3 deletions test/phoenix_ecto/check_repo_status_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,30 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do

conn = conn(:get, "/")

# default is false
exception =
assert_wrapped(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
mock_migrations_fn: mock_migrations_fn,
migration_lock: false
mock_migrations_fn: mock_migrations_fn
)
end)

assert exception.migration_opts == [migration_lock: false]

# can be overridden to true
exception =
assert_wrapped(Phoenix.Ecto.PendingMigrationError, fn ->
CheckRepoStatus.call(
conn,
otp_app: :check_repo_ready,
mock_migrations_fn: mock_migrations_fn,
migration_lock: true
)
end)

assert exception.migration_opts == [migration_lock: true]
after
Application.delete_env(:check_repo_ready, :ecto_repos)
Process.unregister(StorageUpRepo)
Expand Down Expand Up @@ -151,7 +164,7 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do
)
end)

assert exception.migration_opts == [prefix: "tenant_1"]
assert Keyword.get(exception.migration_opts, :prefix) == "tenant_1"
after
Application.delete_env(:check_repo_ready, :ecto_repos)
Process.unregister(StorageUpRepo)
Expand Down