🚧 NestJS + Prisma Multi-Schema Setup Issue

Struggling to configure multi-schema support in Prisma with NestJS? Separated models/ across multiple files in nestjs. Please help me.
No description
3 Replies
Prisma AI Help
Prisma AI Helpβ€’6mo ago
You selected the bot's instantaneous insights. Let me compile your answer right away! Certainly! Prisma now supports splitting your schema into multiple files (multi-file schema) as of v6.7.0. This is ideal for DDD or modular NestJS projects. Here’s how you can set it up: 1. Organize your schema files
Structure your Prisma files like this:
prisma/
β”œβ”€β”€ migrations/
β”œβ”€β”€ models/
β”‚ β”œβ”€β”€ user.prisma
β”‚ β”œβ”€β”€ post.prisma
β”‚ └── ...other model files
└── schema.prisma

prisma/
β”œβ”€β”€ migrations/
β”œβ”€β”€ models/
β”‚ β”œβ”€β”€ user.prisma
β”‚ β”œβ”€β”€ post.prisma
β”‚ └── ...other model files
└── schema.prisma

Place your datasource and generator blocks in schema.prisma. Put your models in separate files under models/ for clarity and modularity. 2. Configure Prisma to use the folder
You must tell Prisma CLI where your schema folder is. You can do this by: - Using the CLI:
npx prisma migrate dev --schema ./prisma

npx prisma migrate dev --schema ./prisma

- Or in package.json:
{
"prisma": {
"schema": "./prisma"
}
}

{
"prisma": {
"schema": "./prisma"
}
}

- Or in prisma.config.ts:
import path from 'node:path'
export default {
earlyAccess: true,
schema: path.join('prisma'),
}

import path from 'node:path'
export default {
earlyAccess: true,
schema: path.join('prisma'),
}

All migrations must be next to the file with the datasource block (usually schema.prisma) Multi-file Prisma schema. 3. Multi-schema (database schemas) support
If you want to use multiple database schemas (e.g., PostgreSQL schemas), enable the multiSchema preview feature and use the schemas field in your datasource block. Assign models to schemas with @@schema("schema_name") How to use Prisma ORM with multiple database schemas. Note:
- Multi-file schema is GA, but multi-database-schema is still in preview. - If you use NestJS, ensure you import the correct generated client if you have multiple clients or outputs. If you run into issues, double-check your CLI commands and file structure. If you need to merge schemas in older Prisma versions, community tools like prisma-import or prisma-merge can help, but native support is now available Multi-file Prisma schema. πŸ€” Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurulβ€’6mo ago
Looks related to this other thread of yours which is resolved? https://discord.com/channels/937751382725886062/1389941146779779123
Sheik Mostafizur
Sheik MostafizurOPβ€’5mo ago
This is solved but I need the schema module base and multi File base because in a single schema.prisma write all schema and handle them not easy. So anyone can't do this?

Did you find this page helpful?