defmodule Example do use Ash.Domain resources do resource Example.DeliveryStatus end end defmodule Example.Repo do use AshPostgres.Repo, otp_app: :example def installed_extensions do ["ash-functions"] end def min_pg_version do %Version{major: 17, minor: 5, patch: 0} end end defmodule Example.PlatformADetails do use Ash.Resource, domain: Example, data_layer: :embedded actions do defaults [:read, :destroy, create: :*, update: :*] end attributes do attribute :name, :string, public?: true end end defmodule Example.Details do use Ash.Type.NewType, subtype_of: :union, constraints: [ types: [ platform_a_details: [ type: Example.PlatformADetails, tag: :type, tag_value: :platform_a ] ] ] end defmodule Example.DeliveryStatus do use Ash.Resource, domain: Example, # The same error will occur when using the :embedded data layer, # but the happy case will not work due to it not supporting upserts/identities # data_layer: :embedded data_layer: AshPostgres.DataLayer postgres do table "delivery_status" repo Example.Repo end code_interface do define :create end actions do create :create do accept :* upsert? true upsert_identity :product_id_platform upsert_fields :replace_all end end identities do identity :product_id_platform, [:product_id, :platform] end attributes do integer_primary_key :id, public?: true attribute :product_id, :integer, allow_nil?: false, public?: true attribute :platform, :atom, constraints: [one_of: [:platform_a, :platform_b]], allow_nil?: false, public?: true attribute :status, :atom, constraints: [one_of: [:not_sent, :sent, :in_progress]], allow_nil?: false, public?: true attribute :details, Example.Details, public?: true end end