Multi schema with files next to code? (Per module)
Hey
I really like the fact Prisma allows to split schemas now, but putting all into single folder isn’t perfect.
Is there any way to be able to put each module schema next to its code to make it easier to maintain and develop?
Like having base schema in root/prisma, but then have eg root/src/users/user.prisma, root/src/tasks/task.prisma etc?
2 Replies
You selected the bot's instantaneous insights. Let me compile your answer right away!
Currently, Prisma’s multi-file schema support requires that all
.prisma
files be located within a single directory (commonly prisma/
or a subdirectory like prisma/models/
). You must specify the path to this directory (not individual files) using the --schema
CLI flag, the prisma.schema
field in package.json
, or the schema
property in prisma.config.ts
. Prisma will then recursively merge all .prisma
files in that directory and its subdirectories, but only within the specified schema folder—not arbitrary locations throughout your project like src/users/user.prisma
or src/tasks/task.prisma
Multi-file Prisma schema docs.
This means you cannot natively colocate schema files next to your code modules (e.g., in src/users/
or src/tasks/
). All schema files must reside under the configured schema directory. The recommended approach is to organize your schema files by domain within the schema folder (e.g., prisma/models/user.prisma
, prisma/models/task.prisma
), but not to place them directly alongside your application code outside of this folderMulti-file Prisma schema docs.
If you want to colocate schema files with code, you would need to use a custom script or community tool to merge them into the schema directory before running Prisma commands. However, this is not officially supported or documented as a best practice by Prisma.
In summary: Native Prisma support for multi-file schemas does not currently allow you to place .prisma
files arbitrarily next to your code modules—they must be within a single, specified schema directoryMulti-file Prisma schema docs.
🤔 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.Hey!
Currently it is not natively supported to put schema files at arbitrary location as in your use case.