Skip to content

Commit 78ae076

Browse files
vanrensbirdclaudeankur-arch
authored
Blog refresh: Organize Your Prisma Schema into Multiple Files (#8017)
Reframe from v5.15 Preview announcement to evergreen guide. The feature went GA in 6.7.0; the old post had a contradictory update-note band-aid on top of Preview-era prose. New answer-first intro, v7 setup with prisma.config.ts schema directory, prisma-client generator, and Prisma Postgres. Adds a verified pitfalls section, including the silent failure where schema pointing at a file instead of the directory generates a client with no models. Setup verified end-to-end on Prisma 7.8.0 (generate, db push, cross-file relation queries). Adds Prisma Next section per refresh policy. Slug, author, and publish date unchanged; updatedAt bumped. Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Ankur Datta <64993082+ankur-arch@users.noreply.github.com>
1 parent 4047636 commit 78ae076

1 file changed

Lines changed: 69 additions & 35 deletions

File tree

  • apps/blog/content/blog/organize-your-prisma-schema-with-multi-file-support
Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,83 @@
11
---
2-
title: "Organize Your Prisma Schema into Multiple Files in v5.15"
2+
title: "Organize Your Prisma Schema into Multiple Files"
33
slug: "organize-your-prisma-schema-with-multi-file-support"
44
date: "2024-06-04"
5+
updatedAt: "2026-07-06"
56
authors:
67
- "Jon Harrell"
7-
metaTitle: "Organize your Prisma Schema into multiple files with Prisma ORM version 5.15.0"
8-
metaDescription: "With Prisma ORM 5.15.0 you can now use multiple Prisma Schema files instead of just one. Learn how to enable this Preview feature and check out a real-world example."
8+
metaTitle: "Organize Your Prisma Schema into Multiple Files"
9+
metaDescription: "Prisma ORM supports splitting your schema into multiple .prisma files, Generally Available since v6.7.0. Learn the Prisma 7 setup with prisma.config.ts, best practices, and common pitfalls."
910
metaImagePath: "/organize-your-prisma-schema-with-multi-file-support/imgs/meta-26e729ad6c2082d921722ad482ef83992eb66f5f-1266x711.png"
1011
heroImagePath: "/organize-your-prisma-schema-with-multi-file-support/imgs/hero-5df6e670b8b37555a5d3caf40521722d9613b705-844x474.svg"
1112
heroImageAlt: "An image showing several .prisma files with the text \"Split your schema!\""
1213
tags:
13-
- "announcement"
1414
- "orm"
15+
- "education"
1516
---
1617

17-
We are excited to introduce a new Preview feature in Prisma ORM: the ability to [organize your Prisma Schema into multiple files](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema). Learn how to implement this in your projects, explore best practices, and check out our sample project for a hands-on example.
18+
Prisma ORM lets you [organize your Prisma Schema into multiple files](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema). You split your models across as many `.prisma` files as you like, relations work across files without any imports, and Prisma combines everything when you run `prisma generate` or a migration command. The feature is Generally Available since v6.7.0, so no preview flag is needed. In Prisma ORM v7, you point the `schema` property in `prisma.config.ts` at the directory that holds your schema files. This post shows the setup, when to split, and the pitfalls to avoid.
1819

19-
> **Update (June 2025)**: This feature went into General Availability in [v6.7.0](https://github.com/prisma/prisma/releases/tag/6.7.0). You now don't need to include it in the `previewFeatures` any more. Learn more in the [docs](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema).
20+
Multi-file schemas were [one of our most requested features](https://github.com/prisma/prisma/issues/2377): they first shipped as the `prismaSchemaFolder` Preview feature in v5.15 and went GA in [v6.7.0](https://github.com/prisma/prisma/releases/tag/6.7.0).
2021

21-
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](https://github.com/prisma/prisma/issues/2377), we hope that you'll try out the `prismaSchemaFolder` Preview feature and let us know what you think on [GitHub](https://github.com/prisma/prisma/discussions/24413). Your continued feedback will help us deliver features like this one!
22-
23-
### What is included in the multi-file Prisma Schema Preview feature
24-
25-
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.
22+
### How to split your Prisma Schema into multiple files
2623

27-
![An image of Visual Studio Code showing multiple .prisma files in a schema sub-directory of the prisma directory.](/organize-your-prisma-schema-with-multi-file-support/imgs/55b449e46a7d01963d4c7a3fdd3bb921b8c4619f-2908x2064.png)
24+
A multi-file schema keeps your main `schema.prisma`, containing the `generator` and `datasource` blocks, at the top of your `prisma` directory, with your models split into files alongside or below it. A common layout groups model files in a `models` subdirectory:
2825

29-
### How to split your Prisma Schema into multiple files
26+
```
27+
prisma/
28+
├── migrations
29+
├── models
30+
│ ├── user.prisma
31+
│ └── post.prisma
32+
└── schema.prisma
33+
```
3034

31-
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](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) in order to take advantage of these updates in your IDE.
35+
In Prisma ORM v7, tell Prisma where your schema directory lives via the `schema` property in `prisma.config.ts`. Note that it points at the directory, not at a single file:
36+
37+
```ts
38+
// prisma.config.ts
39+
import "dotenv/config";
40+
import { defineConfig, env } from "prisma/config";
41+
42+
export default defineConfig({
43+
schema: "prisma/",
44+
migrations: {
45+
path: "prisma/migrations",
46+
},
47+
datasource: {
48+
url: env("DATABASE_URL"),
49+
},
50+
});
51+
```
3252

33-
To split your Prisma Schema into multiple files, first enable the `prismaSchemaFolder` Preview feature by including it in the `previewFeatures` field of your `generator`.
53+
The main `schema.prisma` only carries the `generator` and `datasource` blocks (in v7, the connection URL lives in `prisma.config.ts`, as shown above):
3454

3555
```prisma
36-
datasource db {
37-
provider = "postgresql"
38-
url = env("DATABASE_URL")
56+
// prisma/schema.prisma
57+
generator client {
58+
provider = "prisma-client"
59+
output = "../src/generated/prisma"
3960
}
4061
41-
generator client {
42-
provider = "prisma-client-js"
43-
// previewFeatures = ["prismaSchemaFolder"] // not needed since 6.7.0
62+
datasource db {
63+
provider = "postgresql"
4464
}
4565
```
46-
Then, create a `schema` subdirectory under your `prisma` directory. Make sure to move your `schema.prisma` into this directory to ensure everything works correctly.
4766

48-
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:
67+
If you need a PostgreSQL database for `DATABASE_URL`, the fastest way to get one is [Prisma Postgres](https://www.prisma.io/postgres): running `npm create db` provisions a database and gives you the connection string to put in your `.env` file.
68+
69+
Now you can create model files in your schema directory. All models can be referenced in all files, so relations can cross files like so:
4970

5071
```prisma
51-
// user.prisma
72+
// prisma/models/user.prisma
5273
model User {
5374
id Int @id @default(autoincrement())
5475
name String
5576
posts Post[]
5677
}
5778
```
5879
```prisma
59-
// post.prisma
80+
// prisma/models/post.prisma
6081
model Post {
6182
id Int @id @default(autoincrement())
6283
title String
@@ -65,34 +86,47 @@ model Post {
6586
author User @relation(fields: [authorId], references: [id])
6687
}
6788
```
68-
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.
89+
90+
When running `prisma generate`, all schema files are combined, so your workflow continues as normal. Other Prisma CLI commands, such as `validate` and `format`, work with multi-file schemas too, and the [Prisma VS Code extension](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) understands them as well, including "Go to Definition" across files.
91+
92+
We verified this exact setup on Prisma ORM 7.8.0: `prisma generate`, `prisma db push`, and relation queries across the two files above all work without any flag.
93+
94+
### Common pitfalls
95+
96+
A few things to watch out for, all of which we ran into while testing:
97+
98+
- **Point `schema` at the directory, not the file.** If `prisma.config.ts` says `schema: "prisma/schema.prisma"`, Prisma only reads that one file: `prisma generate` still succeeds, but the generated client silently contains none of the models from your other files. If your models seem to have disappeared after splitting files, check this first.
99+
- **Keep `schema.prisma` directly in the configured directory.** The file with your `generator` block must sit at the top of the directory you configured (e.g. `prisma/schema.prisma`), not in a subdirectory like `prisma/models/`.
100+
- **Keep the `migrations` directory at the same level as `schema.prisma`.**
101+
- **Keep every `.prisma` file inside the configured directory.** Prisma only loads files from the directory you specify, so files outside it are ignored.
69102

70103
### When to use multi-file schemas
71104

72-
Weve heard and seen that as a project grows, a single-file Prisma Schema eventually hits a point where its simply too large to manage effectively. Youll see immediate benefits from this feature if you:
105+
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:
73106

74107
* Have a complex schema: if your schema has large models or complex relations, putting related models into a separate file can help make your schema easier to understand and navigate.
75108
* Have a large team: when you have a single Prisma Schema file and have many developers committing, you could run into some pretty annoying merge conflicts during your day. Separating a large schema into several files can help reduce this pain.
76109

77110
### Tips for multi-file Prisma Schemas
78111

79-
Weve found a few patterns work well with this feature and will help you get the most out of it:
112+
We've found a few patterns work well with this feature and will help you get the most out of it:
80113

81-
* Organize your files by domain: group related models into the same file. For example, keep all user-related models in `user.prisma` while post-related models go in `post.prisma`. Try to avoid having kitchen sink schema files.
114+
* Organize your files by domain: group related models into the same file. For example, keep all user-related models in `user.prisma` while post-related models go in `post.prisma`. Try to avoid having "kitchen sink" schema files.
82115
* Use clear naming conventions: schema files should be named clearly and succinctly. Use names like `user.prisma` and `post.prisma` and not `myModels.prisma` or `CommentFeaturesSchema.prisma`.
83-
* Have an obvious “main” schema file: while you can now have as many schema files as you want, you’ll still need a place where you define the `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.
84-
* Keep all schema files inside your configured schema folder: if you set a custom schema directory in your Prisma configuration, make sure every .prisma file is inside that folder, including your schema.prisma file. Prisma only loads files from the directory you specify, so files outside that folder will be ignored.
116+
* Have an obvious "main" schema file: while you can have as many schema files as you want, you'll still need a place where you define the `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.
85117

86118
### Sample Project
87119

88-
If you’d like to see how this feature looks in the real world, check out our [fork of dub](https://github.com/prisma/dub) from dub.co, one of our favorite OSS projects!
120+
If you'd like to see how this feature looks in the real world, check out our [fork of dub](https://github.com/prisma/dub) from dub.co, one of our favorite OSS projects!
121+
122+
### Looking ahead: Prisma Next
89123

90-
### We Want Your Feedback!
124+
Schema organization is also central to [Prisma Next](https://www.prisma.io/blog/prisma-next-early-access-write-your-contract-prompt-your-agent-ship-your-app), the next generation of Prisma ORM, available in Early Access today and becoming Prisma 8 at GA. In Prisma Next, your schema is a single centralised data contract that both you and your coding agent work against, and you can author it in Prisma Schema Language or in TypeScript, keeping your data model in the same language as your application.
91125

92-
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](https://github.com/prisma/prisma/discussions/24413).
126+
It's fast, too: in [our published benchmark](https://www.prisma.io/blog/prisma-next-performance-benchmark), a fork of the open-source drizzle-benchmarks suite, Prisma Next reaches roughly 90% of the raw `pg` driver's speed and ships a client of about 148.5 KB gzipped. Like Prisma ORM, it pairs with [Prisma Postgres](https://www.prisma.io/postgres) out of the box. For new projects, especially ones built with AI coding agents, it's the direction to watch.
93127

94128
## Where to go next
95129

96-
- [Read the multi-file Prisma schema docs](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema) for the current GA workflow and caveats.
130+
- [Read the multi-file Prisma schema docs](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema) for the current workflow and caveats.
97131
- [Explore Prisma ORM](https://www.prisma.io/orm) if you're evaluating the broader developer workflow around schema design and generated types.
98132
- [Pair it with Prisma Postgres](https://www.prisma.io/postgres) if you want a managed Postgres setup that works naturally with larger Prisma projects.

0 commit comments

Comments
 (0)