Add the "a single DB for all tenants" model of multi-tenancy
See original GitHub issueCurrently, Prisma-multi-tenant uses the “one DB per tenant” model of multi-tenancy. However, we could also add the possibility to use the “a single DB for all tenants” model of multi-tenancy.
Here is how it would work:
pmt init
- Asks which mode to use
- If SingleDB, add a “Tenant { id String @id }” model, add “tenantId: String @default(‘dev’)” on all models
- Migrate DB, then creates the first tenant: “dev”
const multiTenant = new MultiTenantSingleDB({sharedModels: []})
- An option for “shared models” which are shared between tenants (ex: Users?)
const prisma = multiTenant.get('tenant_A')
- Adds a middleware to the PrismaClient that adds
{ where: { tenantId: 'tenant_A' } }
on every queries
- Adds a middleware to the PrismaClient that adds
prisma.users.findMany()
- Same as always!
References:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Multi-tenant SaaS patterns - Azure SQL Database
The simplest multi-tenant database pattern uses a single database to host data for all tenants. As more tenants are added, the database is ......
Read more >Multi-tenancy in SingleStoreDB
In this model, you have one master schema and one version of each of your tables. All customer data is stored in the...
Read more >How to use laravel multi tenant (stancl/tenancy) with single DB ?
We have to add BelongsToTenant trait to all of our tenant-specific models. Say if we want to add tenant_id into the users table...
Read more >Multi-Tenancy Database Design Approaches with SQL Server ...
Approach #1: Single Database, Shared Schema · One database to hold the data for all tenants · Every tenant's data is stored in...
Read more >Multi-tenant Application Database Design | by Blake Howe
As the name implies, a tenant (organization) has its own database. Each time a new tenant is added to the system, a new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey guys ! Any news about single DB for all tenants being supported by Prisma ? As stated, for SaaS entrepreneur this would be a massive plus for Prisma.
this is my WIP take on how to solve this:
Every model in the db has a
tenantId
field, which sadly has to be marked optional, since the prisma calls dont know a middleware is injecting the tenantId