Repository navigation
feat(tenancy): give each tenant its own T&E tables (#99) - #104
Merged
Merged
Conversation
Tenant provisioning (CLI and every startup) now clones the 12 T&E tables from the deployment's T&E schema into tenant_<slug>: columns, defaults, checks, indexes and comments via LIKE ... INCLUDING ALL, then foreign keys, the updated_at function and its triggers re-pointed at the tenant schema. Keys are UUIDs, so tenants share no sequence. Idempotent. T&E mode under a tenant session now loads into that tenant's tables, so the 409 added in #93 is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019YPoXzBSj89ZHgw7nfTmbB
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.
Fixes #99. This implements your 26 Oct decision that T&E mode is per tenant. Part of ART Milestone 2 (BR-36).
Approach: clone instead of rewriting the DDL
#99 proposed extracting the
psqlDDL so the API could run it. Cloning turned out much smaller and leavesbuild/untouched.deploy_all.shstill creates the deployment's T&E schema (for examplete_prod). That schema is the template.provision_te_tables()copies the 12 tables intotenant_<slug>withCREATE TABLE … (LIKE template.t INCLUDING ALL). That covers columns, defaults, CHECKs, NOT NULLs, indexes (including the trigram ones) and comments.set_updated_at()function and its 7 triggers are copied from the catalog, rewritten to point at the tenant schema.create_tenant_admin.pycreates a tenant, and for every tenant at startup. If the template is missing or incomplete, it stops with a message pointing todeploy_all.sh.Evidence
All runs are against local PostgreSQL 16.
scripts/test_report.py --strict)tests/test_tenant_isolation.pyscripts/lint.shThe new isolation tests check that:
tenant_a.organisations, and not in B's tables or the shared schema.ForeignKeyViolation.A bug the tests caught along the way. The first version re-read an exhausted cursor inside a list comprehension, so re-provisioning tried to recreate existing tables. It only showed up against tenants left over from an earlier run. The idempotency test now pins this: with that bug put back, the test fails.
https://claude.ai/code/session_019YPoXzBSj89ZHgw7nfTmbB
Generated by Claude Code