Skip to content

Commit d2719d7

Browse files
ankur-archaidankmcalister
authored andcommitted
fix: clarify config file path better (#7261)
1 parent 77cc0b7 commit d2719d7

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

β€Žcontent/200-orm/100-prisma-schema/10-overview/04-location.mdxβ€Ž

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Run prisma generate to generate Prisma Client.
4848
If you prefer splitting your Prisma schema into multiple files, you can have a setup that looks as follows:
4949

5050
```
51-
.
51+
prisma/
5252
β”œβ”€β”€ migrations
5353
β”œβ”€β”€ models
5454
β”‚ β”œβ”€β”€ posts.prisma
@@ -65,7 +65,7 @@ Multi-file Prisma schemas are Generally Available since [v6.7.0](https://pris.ly
6565

6666
### Usage
6767

68-
When using a multi-file Prisma schema, you must always explicitly specify the location of the directory that contains the `.prisma` file with your `datasource` block.
68+
When using a multi-file Prisma schema, you must always explicitly specify the location of the directory that contains your schema files (including the main `schema.prisma` file with your `generator` block).
6969

7070
You can do this in either of three ways:
7171

@@ -79,14 +79,21 @@ You can do this in either of three ways:
7979
}
8080
}
8181
```
82-
- set the `schema` property in [`prisma.config.ts`](/orm/reference/prisma-config-reference#schema):
82+
- set the `schema` property in [`prisma.config.ts`](/orm/reference/prisma-config-reference#schema) ( for Prisma ORM v7):
8383
```ts
84-
import path from 'node:path'
85-
import type { PrismaConfig } from 'prisma'
86-
87-
export default {
88-
schema: path.join('prisma'),
89-
} satisfies PrismaConfig
84+
import { defineConfig, env } from 'prisma/config'
85+
import 'dotenv/config'
86+
87+
export default defineConfig({
88+
schema: 'prisma/schema.prisma',
89+
migrations: {
90+
path: 'prisma/migrations',
91+
seed: 'tsx prisma/seed.ts',
92+
},
93+
datasource: {
94+
url: env('DATABASE_URL'),
95+
},
96+
})
9097
```
9198

9299
:::note
@@ -95,29 +102,40 @@ You can do this in either of three ways:
95102

96103
:::
97104

98-
All examples above assume that your `datasource` block is defined in a `.prisma` file inside the `prisma` directory.
105+
:::warning
99106

100-
You also must place the `migrations` directory next to the `.prisma` file that defines the `datasource` block.
107+
The `schema.prisma` file (which contains your `generator` block) must be located in the same directory that you specify in your schema configuration. For example, if you configure `schema: 'prisma'`, your `schema.prisma` file must be at `prisma/schema.prisma`, not in a subdirectory like `prisma/models/schema.prisma`.
101108

102-
For example, assuming `schema.prisma` defines the `datasource`, here's how how need to place the migrations folder:
109+
:::
110+
111+
You also must place the `migrations` directory at the same level as your `schema.prisma` file.
112+
113+
For example, assuming `schema.prisma` defines the `generator` block, here's the correct directory structure:
103114

104115
```
105-
# `migrations` and `schema.prisma` must be on the same level
106-
.
116+
# All files must be inside the `prisma/` directory
117+
# `migrations` and `schema.prisma` must be at the same level
118+
prisma/
107119
β”œβ”€β”€ migrations
108120
β”œβ”€β”€ models
109121
β”‚ β”œβ”€β”€ posts.prisma
110122
β”‚ └── users.prisma
111-
└── schema.prisma
123+
└── schema.prisma # Contains generator block
112124
```
113125

126+
:::info
127+
128+
If your schema files are in a `prisma/` directory (as shown above), the Prisma CLI commands like `prisma generate` and `prisma migrate dev` will work without additional configuration, as `./prisma/schema.prisma` is a default location.
129+
130+
:::
131+
114132
### Tips for multi-file Prisma Schema
115133

116134
We've found that a few patterns work well with this feature and will help you get the most out of it:
117135

118136
- 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`.
119137
- 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`.
120-
- 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 `datasource` and `generator` blocks. 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.
138+
- 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 your `generator` block. We recommend having a single schema file that's obviously the "main" file so that this block is easy to find. `main.prisma`, `schema.prisma`, and `base.prisma` are a few we've seen that work well.
121139

122140
### Examples
123141

0 commit comments

Comments
Β (0)