diff --git a/lib/phoenix_ecto/check_repo_status.ex b/lib/phoenix_ecto/check_repo_status.ex index 66e00f5..b8d7fe6 100644 --- a/lib/phoenix_ecto/check_repo_status.ex +++ b/lib/phoenix_ecto/check_repo_status.ex @@ -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 """ @@ -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 diff --git a/test/phoenix_ecto/check_repo_status_test.exs b/test/phoenix_ecto/check_repo_status_test.exs index 9030de2..4dce6c3 100644 --- a/test/phoenix_ecto/check_repo_status_test.exs +++ b/test/phoenix_ecto/check_repo_status_test.exs @@ -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) @@ -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)