Skip to content

feat: apply multitenancy ancestor_attributes to index prefixes, references, and snapshots#804

Open
jechol wants to merge 2 commits into
ash-project:mainfrom
jechol:hierarchical-tenants
Open

feat: apply multitenancy ancestor_attributes to index prefixes, references, and snapshots#804
jechol wants to merge 2 commits into
ash-project:mainfrom
jechol:hierarchical-tenants

Conversation

@jechol

@jechol jechol commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Companion to ash-project/ash#2796 (hierarchical tenants via ancestor_attributes) and ash-project/ash_sql#240. Makes the migration generator and runtime aware of the ancestor chain:

  • identity/reference index tenant prefixes become the full chain ([organization_id, department_id, ...])
  • references that already match on the tenant attribute now match on the full chain — the generated composite foreign keys enforce, at the DB level, that referencing and referenced rows agree on every level of the hierarchy; hierarchies of different depths pair their shared prefix
  • resource snapshots store ancestor_attributes so codegen diffs it correctly; older snapshots without it load as []

Tests: migration-generator coverage (index prefixes, snapshot round-trip, FK chain matching, 3-level chains) plus runtime multitenancy tests against Postgres (cross-organization isolation with colliding department ids, upsert conflict targets).

Proposal issue with the full picture: ash-project/ash#2797.

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

jechol added 2 commits July 23, 2026 09:48
Prefixes identity unique indexes and belongs_to reference indexes with the
tenant's ancestor attributes, pairs ancestor columns into composite foreign
keys (match: :full) between attribute-multitenant resources, and stores
ancestor_attributes in resource snapshots (older snapshots load as []).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant