Since Prisma hasn't introduced any solution for this matter yet, used this awesome package Prismix and solved the issue. Thanks, everyone!
Answer from Farhaan Mahbub on Stack OverflowMultiple Prisma connections and schemas
I would like to use multiple schema files
Prisma adds support for multiple schemas and table views!!
node.js - Prisma: Query across multiple schemas in a database - Stack Overflow
Since Prisma hasn't introduced any solution for this matter yet, used this awesome package Prismix and solved the issue. Thanks, everyone!
Prisma multiSchema is now supported as a preview feature.
See here https://www.prisma.io/docs/guides/database/multi-schema
It was introduced in version 4.3.0 https://github.com/prisma/prisma/issues/1122#issuecomment-1231773471
As the docs say you would add the preview feature...
generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}
Then in your datasource you note the schemas...
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
schemas = ["User", "Post"]
}
And finally in each model you add the @@schema attribute...
model User {
id Int @id @default(autoincrement())
username String @unique @db.VarChar(255)
role UserRole @default(admin)
posts Post[]
@@schema("User")
}
model Post {
id Int @id @default(autoincrement())
title String
post String @db.VarChar(500)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
user_id Int
user User @relation(fields: [user_id], references: [id])
@@schema("Post")
}
Note:
It might not be possible to do cross schema foreign keys. I saw it mentioned somewhere, but I can't find it now.
I was reading through Prisma release notes for versions 4.8.0 and 4.9.0 (as you do), and I saw that they have released support for both views and multiple schemas! This has long been an issue for those of us who have wanted to use Prisma with Supabase, but we've always had to to do hacky things to make it work around Supabase's `auth`, `storage`, and other schemas.
These features are behind preview flags for now, but I'm super excited to see this support coming to the library! Leave a comment if you've been able to test this out at all - I might hack on it a bit this weekend, myself.
https://www.prisma.io/docs/guides/database/multi-schema
https://www.prisma.io/docs/concepts/components/prisma-schema/views
https://github.com/prisma/prisma/releases
That is not yet possible. Here's a GitHub issue that had been created you can use to monitor the feature's status and give your feedback too.
Could you also share your use case too? Your feedback will be highly appreciated as we relay it back to the team. 🙂
Prisma multiSchema is now supported as a preview feature.
See here https://www.prisma.io/docs/guides/database/multi-schema
It was introduced in version 4.3.0 https://github.com/prisma/prisma/issues/1122#issuecomment-1231773471
As the docs say you would add the preview feature...
generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}
Then in your datasource you note the schemas...
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
schemas = ["schema1", "schema2"]
}
And finally in each model you add the @@schema attribute...
model User {
id Int @id
orders Order[]
profile Profile?
@@schema("schema1")
}
model Order {
id Int @id
user User @relation(fields: [id], references: [id])
user_id Int
@@schema("schema2")
}