implement a multi-schema database architecture with Prisma for a B2B SaaS with multiple organization
I'm trying to implement a database architecture with separate schemas for a B2B SaaS application supporting multiple organizations. My desired setup is:
- A public schema for user authentication (tokens, sessions) with next-auth and a global organizations table
- An organization_template schema with pre-populated tables (roles, permissions, organization_details)
- Dynamic creation of new schemas (organization1, organization2, etc.) by cloning the template when a new organization is created
The main issue is that Prisma doesn't natively support multi-schema architecture. The Prisma instance only works with the public schema and doesn't recognize or interact with the dynamically created organization schemas.
7 Replies
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into
#ask-ai
if you get antsy for a second opinion!this is my schema.prisma
this is my next-auth.schema
this is my organization.schema
@🔨 Moderator
Please don't tag mods unless someone has broke the rules. Someone will help when they can :)
If I understand correctly, you would like to achieve the setup as described in this feature request, right?
https://github.com/prisma/prisma/issues/12420
GitHub
Isolating multi-tenant data via database schemas · Issue #12420 · p...
Problem Multi-tenant applications want to leverage per tenant schemas to implement data isolation. Suggested solution a shared model referencing a schema that holds tenant information one or more t...
not really, i don't want to declare all my new tenants in schema.prisma file at datasource db schemas array
because all new tenants are created by clients