ash_postgres/test/support/multitenancy/resources/org.ex

54 lines
1 KiB
Elixir
Raw Normal View History

2020-10-29 15:26:45 +13:00
defmodule AshPostgres.MultitenancyTest.Org do
@moduledoc false
use Ash.Resource,
domain: AshPostgres.MultitenancyTest.Domain,
2020-10-29 15:26:45 +13:00
data_layer: AshPostgres.DataLayer
2023-07-13 02:56:15 +12:00
identities do
identity(:unique_by_name, [:name])
2020-10-29 15:26:45 +13:00
end
attributes do
2021-01-13 14:27:39 +13:00
uuid_primary_key(:id, writable?: true)
attribute(:name, :string, public?: true)
2020-10-29 15:26:45 +13:00
end
actions do
default_accept(:*)
2022-04-20 03:08:28 +12:00
defaults([:create, :read, :update, :destroy])
2020-10-29 15:26:45 +13:00
end
postgres do
table "multitenant_orgs"
2022-08-19 06:56:36 +12:00
repo(AshPostgres.TestRepo)
2020-10-29 15:26:45 +13:00
manage_tenant do
2022-08-19 06:56:36 +12:00
template(["org_", :id])
2020-10-29 15:26:45 +13:00
end
end
multitenancy do
2021-01-13 14:22:28 +13:00
strategy(:attribute)
attribute(:id)
global?(true)
parse_attribute({__MODULE__, :tenant, []})
2020-10-29 15:26:45 +13:00
end
relationships do
has_many(:posts, AshPostgres.MultitenancyTest.Post,
destination_attribute: :org_id,
public?: true
)
has_many(:users, AshPostgres.MultitenancyTest.User,
destination_attribute: :org_id,
public?: true
)
2020-10-29 15:26:45 +13:00
end
def tenant("org_" <> tenant) do
tenant
end
end