question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

role-based schema prefix for multi-tenancy apps

See original GitHub issue

Hi, 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:open
  • Created 4 years ago
  • Reactions:26
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
tirumaraiselvancommented, Jun 8, 2020

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 like public_users and tenant1 schema has no prefix and can query simply like users.

I have edited the title to reflect this feature request.

3reactions
Camsteackcommented, May 27, 2022

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 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi tenancy with query prefixes — Ecto v3.9.2 - HexDocs
The idea is that prefixes will provide data isolation between the different users of the application, guaranteeing either globally or at the data...
Read more >
Spring or Hibernate multi-tenancy for multi-database Grails app
The general idea is that a routing DataSource acts as an intermediary - while the 'real' DataSource can be determined dynamically at runtime...
Read more >
Multi Tenancy - Questions / Help - Elixir Forum
I want to convert an existing app to a multi tenancy architecture and will be using Postgres schemas for this. One account will...
Read more >
Multi-tenant Application with Laravel and Postgres - Medium
The first thing we want to do in our multi-tenant web-app is to identify the venture/tenant from whom the request has been made....
Read more >
Unable to prefix cache in Multi tenant App - Laracasts
Hi Everyone, I am following Mohamed Said repo https://github.com/themsaid/multitenancy-example for Multi-tenant Laravel 7 App. As per Mohamed Said youtube ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found