Alternera. Resource. Transformers. AddTenantReferences
(alternera_resource_sdk v0.9.0)
Copy Markdown
View Source
Keeps every reference between records inside one tenant, in the database.
Each belongs_to of the resource gets an AshPostgres reference with
match_with: [tenant_id: :tenant_id] and match_type: :simple, so its
foreign key is (<ref>_id, tenant_id) → (id, tenant_id) and the database
refuses a record that names another tenant's; SIMPLE lets an empty
reference pass. Not AshPostgres's match_tenant?: it adds the tenant
column only when the migration is rendered, so the generator does not
order the key after the target's unique index and Postgres refuses it.
A reference the package declared keeps its other options (on_delete, a
name); one it did not declare is added with on_delete: :restrict.
The foreign key needs a unique key on the target's (tenant_id, <primary key>), so every resource gets an identity :alternera_tenant_key on its
primary key, which attribute multitenancy makes a unique index on
(tenant_id, <primary key>). It also serves every query by tenant.
Summary
Functions
Callback implementation for Spark.Dsl.Transformer.after?/1.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.
Functions
Callback implementation for Spark.Dsl.Transformer.after?/1.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.