mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 13:33:50 +12:00
37cc01957d
* 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`
53 lines
1 KiB
Elixir
53 lines
1 KiB
Elixir
defmodule AshPostgres.MultitenancyTest.Org do
|
|
@moduledoc false
|
|
use Ash.Resource,
|
|
domain: AshPostgres.MultitenancyTest.Domain,
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
identities do
|
|
identity(:unique_by_name, [:name])
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key(:id, writable?: true)
|
|
attribute(:name, :string, public?: true)
|
|
end
|
|
|
|
actions do
|
|
default_accept(:*)
|
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
end
|
|
|
|
postgres do
|
|
table "multitenant_orgs"
|
|
repo(AshPostgres.TestRepo)
|
|
|
|
manage_tenant do
|
|
template(["org_", :id])
|
|
end
|
|
end
|
|
|
|
multitenancy do
|
|
strategy(:attribute)
|
|
attribute(:id)
|
|
global?(true)
|
|
parse_attribute({__MODULE__, :tenant, []})
|
|
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
|
|
)
|
|
end
|
|
|
|
def tenant("org_" <> tenant) do
|
|
tenant
|
|
end
|
|
end
|