#implement a multi-schema database architecture with Prisma for a B2B SaaS with multiple organization
1 messages · Page 1 of 1 (latest)
this is my schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
previewFeatures = ["prismaSchemaFolder", "multiSchema"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
schemas = ["public", "organization_template"]
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime? @map("email_verified")
passwordHash String? @map("password_hash")
image String?
accounts Account[]
sessions Session[]
ownedOrganization Organization?
isAdmin Boolean @default(false) @map("is_admin")
members Member[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("users")
@@schema("public")
}
model Organization {
id String @id @default(cuid())
name String
schemaName String @unique @map("schema_name")
slug String @unique @default(nanoid(6))
image String?
ownerId String @unique @map("owner_id")
owner User @relation(fields: [ownerId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
members Member[]
Licence Licence[]
@@map("organizations")
@@schema("public")
}
this is my next-auth.schema
// DO NOT EDIT THIS FILE !
// All this tables is defined by following the documentation of Authjs
// See : https://authjs.dev/getting-started/adapters/prisma?framework=next-js
model Account {
id String @id @default(cuid())
userId String @map("user_id")
type String
provider String
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
@@schema("public")
}
model Session {
id String @id @default(cuid())
sessionToken String @unique @map("session_token")
userId String @map("user_id")
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("sessions")
@@schema("public")
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
data Json?
@@unique([identifier, token])
@@map("verification_tokens")
@@schema("public")
}
this is my organization.schema
<@&937755430136995890>
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
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 authentificated user in my app so it's dynamic schemas