ash_postgres/test/support/multitenancy/resources/user.ex
Zach Daniel 37cc01957d
improvement!: 3.0 (#227)
* WIP

* chore: fix mix.lock merge issues

* improvement: upgrade to 3.0

* chore: remove `repo.to_tenant`

* chore: continue removal of unnecessary helper

* chore: use `Ash.ToTenant`
2024-03-27 16:52:28 -04:00

40 lines
900 B
Elixir

defmodule AshPostgres.MultitenancyTest.User do
@moduledoc false
use Ash.Resource,
domain: AshPostgres.MultitenancyTest.Domain,
data_layer: AshPostgres.DataLayer
attributes do
uuid_primary_key(:id, writable?: true)
attribute(:name, :string, public?: true)
attribute(:org_id, :uuid, public?: true)
end
postgres do
table "users"
repo AshPostgres.TestRepo
end
actions do
default_accept(:*)
defaults([:create, :read, :update, :destroy])
end
multitenancy do
# Tells the resource to use the data layer
# multitenancy, in this case separate postgres schemas
strategy(:attribute)
attribute(:org_id)
parse_attribute({__MODULE__, :parse_tenant, []})
global?(true)
end
relationships do
belongs_to(:org, AshPostgres.MultitenancyTest.Org) do
public?(true)
end
end
def parse_tenant("org_" <> id), do: id
end