Skip to content

Support for splitting Prisma schema into multiple files #2377

Description

@albertoperdomo

Problem

Prisma currently only supports one single Prisma Schema file. Developers want more flexibility for managing their Prisma Schema files.

Motivations:

  • breaking up large schema files to make them more manageable
  • flexible integration with certain architectures, i.e. each module has its own self-contained logic including its schema

Solution

Support importing additional schema files, i.e. import "user.schema", import models/*.prisma or import modules/**/*.prisma.

Alternatives

Not researched at this time.

Additional context

#92

Activity

  1. ChristophDietrich commented on May 8, 2020

    @ChristophDietrich

    Like prisma one ... there was a feature like this implemented.

  2. paniavula commented on May 14, 2020

    @paniavula

    Appreciate prioritisation of this. It is really painful to write all the schema in one file.

  3. beeplin commented on May 14, 2020

    @beeplin

    badly need this feature. currently I have to cat a.prisma b.prisma > schema.prisma. it works but is so clumsy.

  4. JontyCoertzen commented on Jun 2, 2020

    @JontyCoertzen

    Any update on this?

  5. SteveSonoa commented on Nov 13, 2020

    @SteveSonoa

    Any movement on this? Really looking for this solution.

  6. yhaiovyi commented on Nov 14, 2020

    @yhaiovyi

    It's a dealbreaker for me...

  7. Mark-Panda commented on Nov 20, 2020

    @Mark-Panda
  8. tylim88 commented on Nov 29, 2020

    @tylim88
  9. cudba commented on Nov 30, 2020

    @cudba

    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.

  10. hgezim commented on Jan 2, 2021

    @hgezim

    Ideally, I'd like my models to live near their/in modules in Nest.

  11. slinden2 commented on Jan 2, 2021

    @slinden2

    Would be a nice feature. A single file is not maintainable.

  12. 375 remaining items

  13. aseemk commented on May 17, 2024

    @aseemk

    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!

  14. darkartur commented on May 25, 2024

    @darkartur

    No with react native support this makes even more sense if someone decides to share schema between backend and react native app

  15. dolapo1 commented on May 30, 2024

    @dolapo1

    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.prisma
    

    config.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 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

    npx prisma migrate dev --name init

  16. dolapo1 commented on May 30, 2024

    @dolapo1

    I found this somewhere.

  17. nlynzaad commented on May 31, 2024

    @nlynzaad

    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

  18. added this to the 5.15.0 milestone on Jun 4, 2024
  19. janpio commented on Jun 4, 2024

    @janpio
    Contributor

    Hey, we just released support for multiple-file Prisma Schema setups! It is behind the prismaSchemaFolder preview feature:

    Please try it out and leave feedback in this discussion: #24413

  20. locked as resolved and limited conversation to collaborators on Jun 4, 2024
  21. removed this from the 5.15.0 milestone on Jun 6, 2024
  22. removed their assignment
    on Nov 1, 2024
  23. FGoessler commented on Mar 20, 2025

    @FGoessler
    Contributor

    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.

  24. wmadden commented on Jun 10, 2025

    @wmadden
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions