role-based schema prefix for multi-tenancy apps
See original GitHub issueHi, we’re currently exploring ways to add a GraphQL API to our existing SaaS multi tenant application. We currently use postgres schemas to isolate our clients and each client has identical tables, etc. in their schema. For example
myapp (database)
- client1 (schema)
- users (table)
- products (table)
- client2 (schema)
- users (table)
- products (table)
All tenants share the same code base and the code simply does a SET search_path <name>
to select the schema based of the subdomain, e.g client1.myapp.com.
Hasura looks amazing but we’re not really sure how we can replicate this functionality as it seems to fail at the first hurdle. When we go to track our existing tables it’s populating them with the tenant name (e.g client1_users, should just be users) and we’re not sure how to perform this transparent schema switching.
Is there any way we can accomplish this with Hasura? We’d really love to use this project!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:26
- Comments:14 (5 by maintainers)
One idea is to have a default schema per role (default: public). Say, a role called tenant1 can specify that its default schema is
tenant1
. Then the public schema tables can get a prefix likepublic_users
andtenant1
schema has no prefix and can query simply likeusers
.I have edited the title to reflect this feature request.
It would be great to have something like that ! My main issue personally is that each schema needs to have a complete set of duplicate metadata so it makes it really difficult to apply updates once you start have more than a few tenants. Is there a plan or a way to handle that better where we could only have one set of files that we could apply to each schema ? That would be awesome as at the moment the only viable way to have a multi tenant environment is to use one schema with a tenant column. Thanks a lot for the awesome product though !