Repository navigation
Support for splitting Prisma schema into multiple files #2377
Description
Activity
- addedkind/featureA request for a new feature.A request for a new feature.
on May 5, 2020 Like prisma one ... there was a feature like this implemented.
Reacted by Guillaume P, Michael Li, McKayla はな , haitam, Newerton, Okan YILDIRIM, Adison Masih, ArthurDev, Serge Deugoue, Nishant Sah and 13 moreAppreciate prioritisation of this. It is really painful to write all the schema in one file.
Reacted by beeman, Guillaume P, Universe, Eduardo Hidalgo, Kalle, Henrikh Kantuni, Roman Prystatskyy, Michael Li, yazer79, McKayla はな and 157 moreReacted by DevScriptbadly need this feature. currently I have to
cat a.prisma b.prisma > schema.prisma. it works but is so clumsy.Reacted by beeman, Isaias Valencia, Universe, Nikolas, Guillaume P, Emrah Bilbay, Eunchurn Park, Eduardo Hidalgo, Ting-Hsiang Hsu, Kalle and 108 moreReacted by Manav Misra, Newerton, Marcos Dourado, Gabriel Cortés Garcia, Andrew Webb, Ishmam and Mostafa FAny update on this?
Reacted by Benoît Jeaurond, techo207, Kalle, Guillaume P, Abner Tellez, 'Damilare Darmie Akinlaja, Aitor C., Paul Dejean, Alesso, galkatz373 and 64 moreReacted by Manav Misra, Lukáš Fuchs, Gio and Eugene MoshchynReacted by Kalle, Xayah Dupont, KimSeungYeop, Guillaume P, Aitor C., Stefano Cicatiello, Bruno Casado, Sébastien Vanvelthem, chihabeeddine, Yannick Tamburrini and 15 moreAny movement on this? Really looking for this solution.
Reacted by beeman, Domagoj Vukovic, Quinn Vaughn, Tomáš Hapl, Joe, Joe Balancio, SCD, slinden2, Iurii, Onur Guvenc and 42 moreIt's a dealbreaker for me...
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 moreReacted by Jiri Spac, Newerton, Hafiz Temuri, Kumar Shantanu, LuanComputacao, Just.Chola and Luis E. Banegas SaybeReacted by drekthral and bartoszredziniakReacted by beeman, Joe, wadhah mahrouk, Martyn Rushton, Nicholas Main, Onur Guvenc, Shemm Junior, Julian, Vasanth Srivatsa, João Brilhante and 17 moreReacted by ckvv, Luis dos Reis, Eugene Moshchyn, (Rew) Andrew McLagan, Nazmi Yılmaz, Azzaz, Naman Jangid, Nicolas Goldenberg and Maxime Ben Hassenuntil 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 moreReacted by Florian Rossiaud, bobby, Wilker Ribeiro, Abdulrahman, frboivin, Camille Louédoc-Eyriès, AlfaHound, Eugene Moshchyn, Pterygoidien and EduardoIdeally, 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 moreReacted by Abdel, Eugene Moshchyn, (Rew) Andrew McLagan, Paulie, Christopher Downard, Pterygoidien, Shahan Neda, John Kidd, Nikola Madic, Naman Jangid and 1 moreWould be a nice feature. A single file is not maintainable.
Reacted by beeman, alaa, Marian Galik, pxDot, bobby, yazer79, GG Nam, Gabriel Rocha de Oliveira, Onur Guvenc, Rodrigo Moreno and 67 moreReacted by Jiri Spac375 remaining items
Load more actionsWell 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 WanagoNo with react native support this makes even more sense if someone decides to share schema between backend and react native app
Create a folder called models in your prisma folder, then add our files to it:
mkdir prisma/models touch prisma/models/config.prisma touch prisma/models/user.prisma touch prisma/models/post.prismaconfig.prisma
generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") }user.prisma
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 filerm -rf ../schema.prisma
We add the content of our models to the main filecat *.prisma >> ../schema.prisma
We format and fix errorsprisma 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 runnpx prisma migrate dev --name initI found this somewhere.
seems like the wait is just about over PR
X (Twitter) TeaserHuge 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 moreReacted by Michael Young, Nathan Chapman, beeman, Sam Waterbury, Marcin Wanago and Yash TotaleHey, we just released support for multiple-file Prisma Schema setups! It is behind the
prismaSchemaFolderpreview feature:- Release Notes: https://github.com/prisma/prisma/releases/tag/5.15.0
- Documentation: https://prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema
- Announcement blog post: https://www.prisma.io/blog/organize-your-prisma-schema-with-multi-file-support
Please try it out and leave feedback in this discussion: #24413
- locked as resolved and limited conversation to collaborators
on Jun 4, 2024 - addedstatus/is-preview-featureThis feature request is currently available as a Preview feature.This feature request is currently available as a Preview feature.
on Jun 5, 2024 - addedtopic: prismaSchemaFolderMulti-File Prisma SchemaMulti-File Prisma Schema
on 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.- 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.tsto point to a folder or file.
For more details see #26663 until we updated the documentation.
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
Problem
Prisma currently only supports one single Prisma Schema file. Developers want more flexibility for managing their Prisma Schema files.
Motivations:
Solution
Support importing additional schema files, i.e.
import "user.schema",import models/*.prismaorimport modules/**/*.prisma.Alternatives
Not researched at this time.
Additional context
#92