Skip to content

Commit 95fde93

Browse files
authored
Disable migration lock by default on CheckRepoStatus (#196)
1 parent c131a74 commit 95fde93

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

lib/phoenix_ecto/check_repo_status.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Phoenix.Ecto.CheckRepoStatus do
99
1010
* `:otp_app` - name of the application which the repos are fetched from
1111
* `: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
12-
* `:migration_lock` - the locking strategy used by the Ecto Adapter when checking for pending migrations. Set to `false` to disable migration locks.
12+
* `: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.
1313
* `:prefix` - the prefix used to check for pending migrations.
1414
* `: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
1515
"""
@@ -67,7 +67,11 @@ defmodule Phoenix.Ecto.CheckRepoStatus do
6767
end)
6868

6969
true = is_function(migrations_fun, 3)
70-
migration_opts = Keyword.take(opts, @migration_opts)
70+
71+
migration_opts =
72+
opts
73+
|> Keyword.take(@migration_opts)
74+
|> Keyword.put_new(:migration_lock, false)
7175

7276
try do
7377
repo

test/phoenix_ecto/check_repo_status_test.exs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,30 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do
111111

112112
conn = conn(:get, "/")
113113

114+
# default is false
114115
exception =
115116
assert_wrapped(Phoenix.Ecto.PendingMigrationError, fn ->
116117
CheckRepoStatus.call(
117118
conn,
118119
otp_app: :check_repo_ready,
119-
mock_migrations_fn: mock_migrations_fn,
120-
migration_lock: false
120+
mock_migrations_fn: mock_migrations_fn
121121
)
122122
end)
123123

124124
assert exception.migration_opts == [migration_lock: false]
125+
126+
# can be overridden to true
127+
exception =
128+
assert_wrapped(Phoenix.Ecto.PendingMigrationError, fn ->
129+
CheckRepoStatus.call(
130+
conn,
131+
otp_app: :check_repo_ready,
132+
mock_migrations_fn: mock_migrations_fn,
133+
migration_lock: true
134+
)
135+
end)
136+
137+
assert exception.migration_opts == [migration_lock: true]
125138
after
126139
Application.delete_env(:check_repo_ready, :ecto_repos)
127140
Process.unregister(StorageUpRepo)
@@ -151,7 +164,7 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do
151164
)
152165
end)
153166

154-
assert exception.migration_opts == [prefix: "tenant_1"]
167+
assert Keyword.get(exception.migration_opts, :prefix) == "tenant_1"
155168
after
156169
Application.delete_env(:check_repo_ready, :ecto_repos)
157170
Process.unregister(StorageUpRepo)

0 commit comments

Comments
 (0)