ash_postgres/lib/transformers/verify_repo.ex
2020-10-28 23:53:28 -04:00

19 lines
509 B
Elixir

defmodule AshPostgres.Transformers.VerifyRepo do
@moduledoc "Verifies that the repo is configured correctly"
use Ash.Dsl.Transformer
def transform(resource, dsl) do
repo = AshPostgres.repo(resource)
cond do
!Code.ensure_loaded?(repo) ->
{: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