You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for splitting Prisma schema into multiple files #2377
Reacted by William Luke, Roy Razon, Salvatore, Christoph Dietrich, Alesso, beeman, Harshit Pant, Jack Davies, paniavula, Orlando Del Aguila and 1296 more
Reacted by AmitGutpa, Joe, Tyler Lu, Johann Buscail, beegeeta, Vitalii Honchar, Yoshiki, knnth, Suchismita Goswami, Trey Martin and 64 more
Reacted by Joe, Tyler Lu, Alex Ruheni, Maxime Golfier, Johann Buscail, Tarcizio Barbosa, Oleg Komarov, Yoshiki, Vũ, Evgenii Perminov and 81 more
Reacted by Duniyal Rasouli, Volodymyr, Marcin Wanago, akirarika, Hélio Costa, Anthony White, Dexter Miguel, Kenyon Kowal, Gilad and bartoszredziniak
Reacted by Eunchurn Park, Guillaume P, Benoît Jeaurond, Rod, Ilshat Khamitov, techo207, Bruno Antunes, Christian Rauchenwald, Xayah Dupont, Jakob Norlin and 164 more
Reacted by Ghalib Ansari, João Koritar, Mr-struct, Tarik Lafi, trust96, Adrian Jose Wix Torres, Luis dos Reis, HeavenOSK, Maxime, Felipe R. Rêgo and 67 more
Reacted by ckvv, Angelo Moreira, Tyler Lu, Gabriel Mesquita, Maxime Golfier, Johann Buscail, Rodrigo Moreno, Luca Fiorani, Jo, Adam Bosco and 101 more
Reacted by Benoît Jeaurond, techo207, Kalle, Guillaume P, Abner Isaac Tellez, 'Damilare Darmie Akinlaja, Aitor C., Paul Dejean, Alesso, galkatz373 and 64 more
Reacted by Manav Misra, Lukáš Fuchs, Gio and Eugene Moshchyn
Reacted by Kalle, Xayah Dupont, KimSeungYeop, Guillaume P, Aitor C., Stefano Cicatiello, Bruno Casado, Sébastien Vanvelthem, chihabeeddine, Yannick Tamburrini and 15 more
Reacted by alex, Frederik Kammer, Justin, Mehmet Efe Akça, Juan David Suárez, AlfaHound, Preeti Yuankrathok, J-Sek, Edward Kerckhof, Jason Buffet and 59 more
Reacted by Jiri Spac, Newerton, Hafiz Temuri, Kumar Shantanu, LuanComputacao, Just.Chola and Luis E. Banegas Saybe
Reacted by drekthral and bartoszredziniak
Reacted by beeman, Joe, wadhah mahrouk, Martyn Rushton, Nicholas Main, Onur Guvenc, Shemm Junior, Julian, Vasanth Srivatsa, João Brilhante and 17 more
Reacted by ckvv, Luis dos Reis, Eugene Moshchyn, (Rew) Andrew McLagan, Nazmi Yılmaz, Azzaz, Naman Jangid, Nicolas Goldenberg and Maxime Ben Hassen
until this is part of the prisma cli, we extracted a small script which we use internally into this tiny cli prisma-merge. its nothing fancy but works for us currently. feel free to use it or copy the source and tailor it to your needs.
Reacted by Domagoj Vukovic, Ilshat Khamitov, Paul Dejean, Quinn Vaughn, SCD, Angelo Moreira, Darian Moody, Eduardo Zamora, Onur Guvenc, Kresimir Cosic and 36 more
Reacted by Florian Rossiaud, bobby, Wilker Ribeiro, Abdul, frboivin, Camille Louédoc-Eyriès, AlfaHound, Eugene Moshchyn, Pterygoidien and Eduardo
Ideally, I'd like my models to live near their/in modules in Nest.
Reacted by beeman, klebersm, Bruce Shi, pxDot, bobby, Alaa, Onur Guvenc, Matko Bulić, Thomas Meitz, Hannes and 68 more
Reacted by Abdel, Eugene Moshchyn, (Rew) Andrew McLagan, Paulie, Christopher Downard, Pterygoidien, Shahan Neda, John Kidd, Nikola Madic, Naman Jangid and 1 more
Well spotted @nlynzaad, we have indeed started work on this functionality. We'll post an update here when there is something ready to play and test with.
This is awesome @janpio, thank you! Our own schema file is at almost 1,500 LOC now, so we'd love a split. =)
If it's helpful from a design perspective, just wanted to request the ability for schema files to be split up across separate folders too, not necessarily all in one. We organize our codebase how the OP here described:
flexible integration with certain architectures, i.e. each module has its own self-contained logic including its schema
(And we've been finding that extremely nice and helpful.)
Thanks again!
Reacted by joacoespinosa, Kyoichiro Yamada and Marcin Wanago
model User {
id Int @id @default(autoincrement())
username String @unique
email String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
posts Post[]
}
post.prisma
model Post {
id Int @id @default(autoincrement())
title String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
author User @relation(fields: [authorId], references: [id])
authorId Int
}
The merging step.
This is where the magic happens, thanks to a single command, we will merge our models into the main schema.prisma file:
cd ./prisma/models && rm -rf ../schema.prisma && cat *.prisma >> ../schema.prisma && cd .. && prisma format
Breakdown of the command:
We change the current dir
cd ./prisma/models
We delete the content of the main file
rm -rf ../schema.prisma
We add the content of our models to the main file
cat *.prisma >> ../schema.prisma
We format and fix errors
prisma format You can add the following to your package.json so that you can just run npm run gen:schema:
"gen:schema": "cd ./prisma/models && rm -rf ../schema.prisma && cat *.prisma >> ../schema.prisma && cd .. && prisma format",
After this step, just run
Huge thanks to all the developers for their efforts on this. Been stalking the pull requests on this and it seems to have been quite the undertaking
Reacted by Nico Lynzaad, Michael Young, Nathan Chapman, Superordi45, beeman, willieee802, Sennay, Sam Waterbury, Marcin Wanago, Preeti Yuankrathok and 2 more
Reacted by Michael Young, Nathan Chapman, beeman, Sam Waterbury, Marcin Wanago and Yash Totale
With Prisma 6.6.0 (scheduled for early April) we will do some changes to details on how the schema folder feature works. With Prisma 6.7.0 we plan to move this preview feature to GA.
Summary of the upcoming changes:
./prisma/schema as a folder is not checked by default anymore.
Migrations, views and typed sql folders are placed next to the schema file that contains the datasource block.
We use a universal schemaPath property in prisma.config.ts to point to a folder or file.
For more details see #26663 until we updated the documentation.
Activity
ChristophDietrich commentedon May 8, 2020
Like prisma one ... there was a feature like this implemented.
paniavula commentedon May 14, 2020
Appreciate prioritisation of this. It is really painful to write all the schema in one file.
beeplin commentedon May 14, 2020
badly need this feature. currently I have to
cat a.prisma b.prisma > schema.prisma. it works but is so clumsy.JontyCoertzen commentedon Jun 2, 2020
Any update on this?
SteveSonoa commentedon Nov 13, 2020
Any movement on this? Really looking for this solution.
yhaiovyi commentedon Nov 14, 2020
It's a dealbreaker for me...
Mark-Panda commentedon Nov 20, 2020
tylim88 commentedon Nov 29, 2020
cudba commentedon Nov 30, 2020
until this is part of the prisma cli, we extracted a small script which we use internally into this tiny cli prisma-merge. its nothing fancy but works for us currently. feel free to use it or copy the source and tailor it to your needs.
hgezim commentedon Jan 2, 2021
Ideally, I'd like my models to live near their/in modules in Nest.
slinden2 commentedon Jan 2, 2021
Would be a nice feature. A single file is not maintainable.
375 remaining items
aseemk commentedon May 17, 2024
This is awesome @janpio, thank you! Our own schema file is at almost 1,500 LOC now, so we'd love a split. =)
If it's helpful from a design perspective, just wanted to request the ability for schema files to be split up across separate folders too, not necessarily all in one. We organize our codebase how the OP here described:
(And we've been finding that extremely nice and helpful.)
Thanks again!
darkartur commentedon May 25, 2024
No with react native support this makes even more sense if someone decides to share schema between backend and react native app
dolapo1 commentedon May 30, 2024
Create a folder called models in your prisma folder, then add our files to it:
config.prisma
user.prisma
The merging step.
This is where the magic happens, thanks to a single command, we will merge our models into the main schema.prisma file:
cd ./prisma/models && rm -rf ../schema.prisma && cat *.prisma >> ../schema.prisma && cd .. && prisma formatBreakdown of the command:
We change the current dir
cd ./prisma/modelsWe delete the content of the main file
rm -rf ../schema.prismaWe add the content of our models to the main file
cat *.prisma >> ../schema.prismaWe format and fix errors
prisma formatYou can add the following to your package.json so that you can just run npm run gen:schema:"gen:schema": "cd ./prisma/models && rm -rf ../schema.prisma && cat *.prisma >> ../schema.prisma && cd .. && prisma format",After this step, just run
npx prisma migrate dev --name initdolapo1 commentedon May 30, 2024
I found this somewhere.
nlynzaad commentedon May 31, 2024
seems like the wait is just about over PR
X (Twitter) Teaser
Huge thanks to all the developers for their efforts on this. Been stalking the pull requests on this and it seems to have been quite the undertaking
janpio commentedon Jun 4, 2024
Hey, we just released support for multiple-file Prisma Schema setups! It is behind the
prismaSchemaFolderpreview feature:Please try it out and leave feedback in this discussion: #24413
FGoessler commentedon Mar 20, 2025
With Prisma 6.6.0 (scheduled for early April) we will do some changes to details on how the schema folder feature works. With Prisma 6.7.0 we plan to move this preview feature to GA.
Summary of the upcoming changes:
./prisma/schemaas a folder is not checked by default anymore.prisma.config.tsto point to a folder or file.For more details see #26663 until we updated the documentation.
wmadden commentedon Jun 10, 2025
Since this is now available in GA, I'm going to go ahead and close this issue.
You can read more about how to use this feature in the Prisma docs: https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema