Modeling Context Multitenancy

The goal is to have a Tenant be identified by a subdomain (I think this is the common usage). I want to use schema/context multitenancy. There is a User resource in the "master" database (master registry?) who are admins that manage tenants. There is another User resource (ideally inheriting from the master User) that represents a user in a tenant. I'm getting back to this thread a month later: https://discord.com/channels/711271361523351632/1098462406109311108/1098614600917852231 in which @Zach Daniel recommended a context-tenanted User resource and an attribute-tenanted Organization resource. Am I missing another resource like Tenant? Otherwise how would attribute-tenancy work for Organization?
3 Replies
ZachDaniel
ZachDaniel2y ago
You can have the tenant identifier be an attribute on resource like maybe id or something like that It should map to the schema name produced for each tenant
Terris
TerrisOP2y ago
@Zach Daniel In the thread linked above, you seemed to be recommending combing context and attribute multitenancy where only the Organization would be attribute tenanted. Did I misread that? "I've done multitenancy setups before and have been able to do it with a tenanted users table, and an attribute multitenancy organizations table". Perhaps you weren't saying that the Organizations table should be tenanted. At any rate, I recall a conversation on this discord server (which I can no longer find here or via google) about a similar scenario where User needs particle/wave duality -- tenanted and untenanted -- the latter is for managing Organizations
ZachDaniel
ZachDaniel2y ago
Yeah, so my suggestion is to use attribute multitenancy on organizations i.e
# organizations
| name | tenant |
| acme | acme |
# organizations
| name | tenant |
| acme | acme |
Then you'd have your context tenanted tables exist in the acme schema So that when you say set_tenant(query, "acme") it will work in both cases in organizations it will filter, and in the other tables it will choose a prefix

Did you find this page helpful?