ash_postgres/lib/transformers/verify_repo.ex

21 lines
573 B
Elixir
Raw Normal View History

2020-10-29 16:53:28 +13:00
defmodule AshPostgres.Transformers.VerifyRepo do
@moduledoc "Verifies that the repo is configured correctly"
2022-08-19 06:56:36 +12:00
use Spark.Dsl.Transformer
alias Spark.Dsl.Transformer
2020-10-29 16:53:28 +13:00
2022-08-19 06:56:36 +12:00
def transform(dsl) do
repo = Transformer.get_option(dsl, [:postgres], :repo)
2020-10-29 16:53:28 +13:00
cond do
2020-10-29 17:03:43 +13:00
match?({:error, _}, Code.ensure_compiled(repo)) ->
2020-10-29 16:53:28 +13:00
{:error, "Could not find repo module #{repo}"}
repo.__adapter__() != Ecto.Adapters.Postgres ->
{:error, "Expected a repo using the postgres adapter `Ecto.Adapters.Postgres`"}
true ->
{:ok, dsl}
end
end
end