diff --git a/lib/phoenix_ecto/check_repo_status.ex b/lib/phoenix_ecto/check_repo_status.ex index 924d4be..705d558 100644 --- a/lib/phoenix_ecto/check_repo_status.ex +++ b/lib/phoenix_ecto/check_repo_status.ex @@ -28,7 +28,7 @@ defmodule Phoenix.Ecto.CheckRepoStatus do repos = Application.get_env(opts[:otp_app], :ecto_repos, []) for repo <- repos, Process.whereis(repo) do - unless check_pending_migrations!(repo, opts) do + unless check_pending_migrations!(repo, opts, Map.new(repo.config)) do check_storage_up!(repo) end end @@ -51,7 +51,11 @@ defmodule Phoenix.Ecto.CheckRepoStatus do end end - defp check_pending_migrations!(repo, opts) do + defp check_pending_migrations!(_repo, _opts, %{read_only: true}) do + false + end + + defp check_pending_migrations!(repo, opts, _repo_opts) do repo_status = with {:ok, migration_directories} <- migration_directories(repo, opts), {:ok, migrations} <- migrations(repo, migration_directories, opts) do diff --git a/test/phoenix_ecto/check_repo_status_test.exs b/test/phoenix_ecto/check_repo_status_test.exs index b926bec..aed8ca9 100644 --- a/test/phoenix_ecto/check_repo_status_test.exs +++ b/test/phoenix_ecto/check_repo_status_test.exs @@ -17,6 +17,12 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do def __adapter__, do: Adapter end + defmodule StorageReadOnly do + defmodule Adapter, do: def(storage_status(_repo_config), do: :up) + def config, do: [read_only: true] + def __adapter__, do: Adapter + end + defmodule StorageDownRepo do defmodule Adapter, do: def(storage_status(_repo_config), do: :down) def config, do: [] @@ -96,6 +102,24 @@ defmodule Phoenix.Ecto.CheckRepoStatusTest do Process.unregister(StorageUpRepo) end + test "does not raise when there are pending migrations for a read only repo" do + Process.register(self(), StorageReadOnly) + Application.put_env(:check_repo_ready, :ecto_repos, [StorageReadOnly]) + mock_migrations_fn = fn _repo, _directories -> [{:down, 1, "migration"}] end + + conn = conn(:get, "/") + + assert CheckRepoStatus.call( + conn, + otp_app: :check_repo_ready, + mock_default_migration_directory_fn: &default_mock_migration_directory_fn/1, + mock_migrations_fn: mock_migrations_fn + ) + after + Application.delete_env(:check_repo_ready, :ecto_repos) + Process.unregister(StorageReadOnly) + end + test "supports the `ecto_migration_lock` option" do Process.register(self(), StorageUpRepo) Application.put_env(:check_repo_ready, :ecto_repos, [StorageUpRepo])