Best Pratices on prisma.schema location
Hi everyone!
I'm creating a nest microservice app with nestjs with each microservice in a different git repository, but all use the same database.
In the project setup i replace the prisma.schema default localization.
Since I am using DDD architecture, I put it inside infra/database/prisma, could this become a big problem in the future?
2 Replies
You selected the bot's instantaneous insights. Let me compile your answer right away!
Placing your Prisma schema in a custom location like infra/database/prisma is a valid approach and is supported by Prisma. You just need to ensure that the Prisma CLI knows where to find your schema. There are several ways to do this:
- Use the --schema flag with every CLI command.
- Set the schema path in your package.json under the prisma property:
- Use a prisma.config.ts file to specify the schema location.
This setup is officially supported and will not cause issues as long as you consistently configure the schema path for your commands and tooling. Prisma CLI will look for the schema in the location you specify, and this pattern is common for projects that want to organize code according to DDD or other architectural patterns. The only potential downside is the need to keep your configuration consistent across all scripts and environments, but this is manageable with the above methods. There is no indication in the knowledge sources that placing the schema in a non-default location will cause problems in the future, as long as you follow these practices Docs: Schema location.
If you have multiple microservices in different repositories but all use the same database, you may face challenges keeping schemas in sync. Some users solve this by sharing the schema via a package or monorepo, but with separate repos, you’ll need a process to synchronize changes across services if the schema evolves Github Issue #458.
In summary: your approach is fine, just ensure the schema path is configured everywhere you use Prisma.
🤔 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.
Was the bot response not helpful?