defmodule MyApp.MyContext.Event do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "event"
repo MyApp.MyContext.Repo
end
multitenancy do
strategy :attribute
attribute :organization_id
end
attributes do
# Tenancy, Identity and Immutability
# * Primary Key - [:organization_id, :id]
# * need to manually declare id so we do not autogenerate UUID
attribute :organization_id, :uuid, allow_nil?: false, primary_key?: true
attribute :id, :uuid, allow_nil?: false, primary_key?: true
attribute :data, :map
attribute :dataschema, :string
attribute :partitionkey, :string
attribute :sequence, :integer
attribute :source, :string, allow_nil?: false
attribute :subject, :string
attribute :time, :utc_datetime_usec
attribute :type, :string, allow_nil?: false
create_timestamp :created_at
end
identities do
identity :id, [:id]
end
actions do
defaults [:read]
create :add do
upsert? true
upsert_identity :id
upsert_fields([:id])
end
end
end
defmodule MyApp.MyContext.Event do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "event"
repo MyApp.MyContext.Repo
end
multitenancy do
strategy :attribute
attribute :organization_id
end
attributes do
# Tenancy, Identity and Immutability
# * Primary Key - [:organization_id, :id]
# * need to manually declare id so we do not autogenerate UUID
attribute :organization_id, :uuid, allow_nil?: false, primary_key?: true
attribute :id, :uuid, allow_nil?: false, primary_key?: true
attribute :data, :map
attribute :dataschema, :string
attribute :partitionkey, :string
attribute :sequence, :integer
attribute :source, :string, allow_nil?: false
attribute :subject, :string
attribute :time, :utc_datetime_usec
attribute :type, :string, allow_nil?: false
create_timestamp :created_at
end
identities do
identity :id, [:id]
end
actions do
defaults [:read]
create :add do
upsert? true
upsert_identity :id
upsert_fields([:id])
end
end
end