feat: support hierarchical tenants via multitenancy ancestor_attributes#2796
Open
jechol wants to merge 1 commit into
Open
feat: support hierarchical tenants via multitenancy ancestor_attributes#2796jechol wants to merge 1 commit into
jechol wants to merge 1 commit into
Conversation
This was referenced Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds first-class support for hierarchical tenancy (organization → department → team) to attribute multitenancy, while keeping the tenant itself scalar.
Without this, the ancestor level has to be reimplemented by hand on every department-scoped resource: a custom change stamping
organization_idon create, plus hand-rolled index prefixes downstream.What it does (when
ancestor_attributesis configured):ancestors ++ [attribute] ++ identity keys:attributestrategy)Backward compatibility
The tenant stays a single value —
multitenancy_attribute/1and everyAsh.ToTenantcontract are unchanged, so ash_oban/ash_paper_trail/manifest consumers are unaffected. Ancestors are derived from the original tenant via the newAsh.ToAncestorTenantsprotocol with@fallback_to_anyreturning[]: resources that don't opt in (ancestor_attributesdefaults to[]) behave exactly as today, and no existing tenant value needs an implementation.(I first tried making
attributeaccept a list; it broke the scalar-tenant contract across the ecosystem, so I discarded that design in favor of this one.)Implementation
Ash.ToAncestorTenantsprotocol (new),ancestor_attributesDSL option, verifier rulesAsh.Resource.Info.multitenancy_ancestor_attributes/1,multitenancy_attributes/1, andmultitenancy_attribute_values/3— the single entry point the six action paths (read/create/bulk create/update/destroy/seed) reduce overValidation
Full suite green. Also dogfooded on our production app (~55 department-scoped resources): the hand-written organization-stamping change is deleted outright, and the strict raise immediately caught a call site passing a bare integer id as tenant for a department-scoped load.
Companion PRs, opened alongside this one: ash-project/ash_sql#240 (join filters) and ash-project/ash_postgres#804 (index prefixes, composite FK
with_match, snapshots). Proposal issue with the full picture: #2797.Contributor checklist
Leave anything that you believe does not apply unchecked.