apps/blog/content/blog/organize-your-prisma-schema-with-multi-file-support/index.mdx
We are excited to introduce a new Preview feature in Prisma ORM: the ability to organize your Prisma Schema into multiple files. Learn how to implement this in your projects, explore best practices, and check out our sample project for a hands-on example.
Update (June 2025): This feature went into General Availability in v6.7.0. You now don't need to include it in the
previewFeaturesany more. Learn more in the docs.
It’s been a long road, but with Prisma ORM 5.15.0 we are finally introducing the ability to use multiple files in your Prisma Schema. This aims to improve the manageability and organization of your database schema, making it easier to work with larger projects. As one of our most requested features, we hope that you'll try out the prismaSchemaFolder Preview feature and let us know what you think on GitHub. Your continued feedback will help us deliver features like this one!
The new prismaSchemaFolder Preview feature allows you to define multiple files in a schema subdirectory of your prisma directory. Prisma handles the combining of files, allowing you to define a model in one file and then use it in other schema files without the need for importing. We've also included updates to the Prisma Visual Studio Code Extension to handle multiple schema files, including “Go to Definition” and checks for existence.
First, make sure that prisma and @prisma/client have been updated to at least 5.15.0. You’ll also need the latest version (5.15.0) of the Prisma VSCode Extension in order to take advantage of these updates in your IDE.
To split your Prisma Schema into multiple files, first enable the prismaSchemaFolder Preview feature by including it in the previewFeatures field of your generator.
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
// previewFeatures = ["prismaSchemaFolder"] // not needed since 6.7.0
}
Then, create a schema subdirectory under your prisma directory. Make sure to move your schema.prisma into this directory to ensure everything works correctly.
Now, you're able to create additional files in your schema directory! All models can be referenced in all files, so relations can cross files like so:
// user.prisma
model User {
id Int @id @default(autoincrement())
name String
posts Post[]
}
// post.prisma
model Post {
id Int @id @default(autoincrement())
title String
content String
authorId Int
author User @relation(fields: [authorId], references: [id])
}
When running prisma generate all schema files are combined, so your workflow will continue as normal. Other Prisma CLI commands, such as validate and format have also been updated to work with multi-file Prisma Schemas.
We’ve heard and seen that as a project grows, a single-file Prisma Schema eventually hits a point where it’s simply too large to manage effectively. You’ll see immediate benefits from this feature if you:
We’ve found a few patterns work well with this feature and will help you get the most out of it:
user.prisma while post-related models go in post.prisma. Try to avoid having “kitchen sink” schema files.user.prisma and post.prisma and not myModels.prisma or CommentFeaturesSchema.prisma.generator block. We recommend having a single schema file that’s obviously the “main” file so that these blocks are easy to find. main.prisma, schema.prisma, and base.prisma are a few we’ve seen that work well.If you’d like to see how this feature looks in the real world, check out our fork of dub from dub.co, one of our favorite OSS projects!
We'd love to hear your thoughts on this new feature. Please share your feedback and any issues you may encounter by commenting on our dedicated GitHub discussion.