2024-03-28 09:52:28 +13:00
|
|
|
defmodule AshPostgres.Verifiers.ValidateReferences do
|
2023-09-23 08:14:25 +12:00
|
|
|
@moduledoc false
|
2024-03-28 09:52:28 +13:00
|
|
|
use Spark.Dsl.Verifier
|
|
|
|
alias Spark.Dsl.Verifier
|
2022-12-11 09:59:50 +13:00
|
|
|
|
2024-03-28 09:52:28 +13:00
|
|
|
def verify(dsl) do
|
2022-12-11 09:59:50 +13:00
|
|
|
dsl
|
|
|
|
|> AshPostgres.DataLayer.Info.references()
|
|
|
|
|> Enum.each(fn reference ->
|
|
|
|
unless Ash.Resource.Info.relationship(dsl, reference.relationship) do
|
|
|
|
raise Spark.Error.DslError,
|
|
|
|
path: [:postgres, :references, reference.relationship],
|
2024-03-28 09:52:28 +13:00
|
|
|
module: Verifier.get_persisted(dsl, :module),
|
2022-12-11 09:59:50 +13:00
|
|
|
message:
|
|
|
|
"Found reference configuration for relationship `#{reference.relationship}`, but no such relationship exists"
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2024-03-28 09:52:28 +13:00
|
|
|
:ok
|
2022-12-11 09:59:50 +13:00
|
|
|
end
|
|
|
|
end
|