Skip to content

Commit 46e6dd8

Browse files
authored
chore(): update guides to use new config file (#7210)
* chore(): update guides to use new config file * update * update * updates * updats based on feedback * updates
1 parent 6e91b55 commit 46e6dd8

13 files changed

+464
-339
lines changed

content/800-guides/080-turborepo.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Inside the `database` directory, initialize prisma by running:
185185
This will create several files inside `packages/database`:
186186

187187
- A `prisma` directory with a `schema.prisma` file.
188+
- A `prisma.config.ts` file for configuring Prisma
188189
- A Prisma Postgres database.
189190
- A `.env` file containing the `DATABASE_URL` at the project root.
190191
- An `output` directory for the generated Prisma Client as `generated/prisma`.
@@ -193,7 +194,7 @@ In the `packages/database/prisma/schema.prisma` file, add the following models:
193194

194195
```prisma file=packages/database/prisma/schema.prisma
195196
generator client {
196-
provider = "prisma-client-js"
197+
provider = "prisma-client"
197198
output = "../generated/prisma"
198199
}
199200

content/800-guides/090-nextjs.mdx

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ To get started with Prisma, you'll need to install a few dependencies:
7070
<TabItem value="Prisma Postgres (recommended)">
7171
```terminal
7272
npm install prisma tsx --save-dev
73-
npm install @prisma/extension-accelerate @prisma/client
73+
npm install @prisma/extension-accelerate @prisma/client dotenv
7474
```
7575
</TabItem>
7676
<TabItem value="Other databases">
7777
```terminal
7878
npm install prisma tsx --save-dev
79-
npm install @prisma/client
79+
npm install @prisma/client dotenv
8080
```
8181
</TabItem>
8282
</TabbedContent>
@@ -93,6 +93,7 @@ You'll need to answer a few questions while setting up your Prisma Postgres data
9393
This will create:
9494

9595
- A `prisma` directory with a `schema.prisma` file.
96+
- A `prisma.config.ts` file for configuring Prisma
9697
- A Prisma Postgres database.
9798
- A `.env` file containing the `DATABASE_URL` at the project root.
9899
- An `output` directory for the generated Prisma Client as `app/generated/prisma`.
@@ -103,7 +104,7 @@ In the `prisma/schema.prisma` file, add the following models:
103104

104105
```prisma file=prisma/schema.prisma
105106
generator client {
106-
provider = "prisma-client-js"
107+
provider = "prisma-client"
107108
output = "../app/generated/prisma"
108109
}
109110
@@ -133,14 +134,36 @@ model Post {
133134

134135
This creates two models: `User` and `Post`, with a one-to-many relationship between them.
135136

136-
### 2.3. Configure the Prisma Client generator
137+
### 2.3 Add `dotenv` to `prisma.config.ts`
138+
139+
To get access to the variables in the `.env` file, they can either be loaded by your runtime, or by using `dotenv`.
140+
Include an import for `dotenv` at the top of the `prisma.config.ts`
141+
142+
```ts
143+
//add-start
144+
import 'dotenv/config'
145+
//add-end
146+
import { defineConfig, env } from 'prisma/config';
147+
export default defineConfig({
148+
schema: 'prisma/schema.prisma',
149+
migrations: {
150+
path: 'prisma/migrations'
151+
},
152+
engine: 'classic',
153+
datasource: {
154+
url: env('DATABASE_URL'),
155+
},
156+
});
157+
```
158+
159+
### 2.4. Configure the Prisma Client generator
137160

138161
Now, run the following command to create the database tables and generate the Prisma Client:
139162

140163
```terminal
141164
npx prisma migrate dev --name init
142165
```
143-
### 2.4. Seed the database
166+
### 2.5. Seed the database
144167

145168
Add some seed data to populate the database with sample users and posts.
146169

@@ -193,45 +216,24 @@ export async function main() {
193216
main();
194217
```
195218

196-
Now, tell Prisma how to run this script by updating your `package.json`:
197-
198-
```json file=package.json
199-
{
200-
"name": "nextjs-prisma",
201-
"version": "0.1.0",
202-
"private": true,
203-
"scripts": {
204-
"dev": "next dev --turbopack",
205-
"build": "next build",
206-
"start": "next start",
207-
"lint": "next lint"
219+
Now, tell Prisma how to run this script by updating your `prisma.config.ts`:
220+
221+
```ts file=prisma.config.ts
222+
import 'dotenv/config'
223+
import { defineConfig, env } from 'prisma/config';
224+
export default defineConfig({
225+
schema: 'prisma/schema.prisma',
226+
migrations: {
227+
path: 'prisma/migrations',
228+
//add-start
229+
seed: `tsx prisma/seed.ts`,
230+
//add-end
208231
},
209-
// add-start
210-
"prisma": {
211-
"seed": "tsx prisma/seed.ts"
232+
engine: 'classic',
233+
datasource: {
234+
url: env('DATABASE_URL'),
212235
},
213-
// add-end
214-
"dependencies": {
215-
"@prisma/client": "^6.7.0",
216-
"@prisma/extension-accelerate": "^1.3.0",
217-
"next": "15.3.1",
218-
"react": "^19.0.0",
219-
"react-dom": "^19.0.0"
220-
},
221-
"devDependencies": {
222-
"@eslint/eslintrc": "^3",
223-
"@tailwindcss/postcss": "^4",
224-
"@types/node": "^20",
225-
"@types/react": "^19",
226-
"@types/react-dom": "^19",
227-
"eslint": "^9",
228-
"eslint-config-next": "15.3.1",
229-
"prisma": "^6.7.0",
230-
"tailwindcss": "^4",
231-
"tsx": "^4.19.4",
232-
"typescript": "^5"
233-
}
234-
}
236+
});
235237
```
236238

237239

@@ -266,7 +268,7 @@ And open Prisma Studio to inspect your data:
266268
npx prisma studio
267269
```
268270

269-
### 2.5 Set up Prisma Client
271+
### 2.6 Set up Prisma Client
270272

271273
Now that you have a database with some initial data, you can set up Prisma Client and connect it to your database.
272274

content/800-guides/160-tanstack-start.mdx

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ To get started with Prisma, you'll need to install a few dependencies:
310310
<TabItem value="Prisma Postgres (recommended)">
311311
```terminal
312312
npm install prisma tsx --save-dev
313-
npm install @prisma/extension-accelerate @prisma/client
313+
npm install @prisma/extension-accelerate @prisma/client dotenv
314314
```
315315
</TabItem>
316316
<TabItem value="Other databases">
317317
```terminal
318318
npm install prisma tsx --save-dev
319-
npm install @prisma/client
319+
npm install @prisma/client dotenv
320320
```
321321
</TabItem>
322322
</TabbedContent>
@@ -334,6 +334,7 @@ You'll need to answer a few questions while setting up your Prisma Postgres data
334334
This will create:
335335

336336
- A `prisma` directory with a `schema.prisma` file.
337+
- A `prisma.config.ts` file for configuring Prisma
337338
- A Prisma Postgres database.
338339
- A `.env` file containing the `DATABASE_URL` at the project root.
339340
- An `output` directory for the generated Prisma Client as `app/generated/prisma`.
@@ -344,7 +345,6 @@ In `schema.prisma`, create a model for our posts and change the generator to use
344345

345346
```prisma file=prisma/schema.prisma
346347
generator client {
347-
//edit-next-line
348348
provider = "prisma-client"
349349
output = "../app/generated/prisma"
350350
}
@@ -375,27 +375,46 @@ model Post {
375375

376376
This creates two models: `User` and `Post`, with a one-to-many relationship between them.
377377

378-
### 2.3. Configure the Prisma Client generator
378+
### 2.3 Add `dotenv` to `prisma.config.ts`
379+
380+
To get access to the variables in the `.env` file, they can either be loaded by your runtime, or by using `dotenv`.
381+
Include an import for `dotenv` at the top of the `prisma.config.ts`
382+
383+
```ts
384+
//add-start
385+
import 'dotenv/config'
386+
//add-end
387+
import { defineConfig, env } from 'prisma/config';
388+
export default defineConfig({
389+
schema: 'prisma/schema.prisma',
390+
migrations: {
391+
path: 'prisma/migrations',
392+
},
393+
engine: 'classic',
394+
datasource: {
395+
url: env('DATABASE_URL'),
396+
},
397+
});
398+
```
399+
400+
### 2.4. Configure the Prisma Client generator
379401

380402
Now, run the following command to create the database tables and generate the Prisma Client:
381403

382404
```terminal
383405
npx prisma migrate dev --name init
384406
```
385-
### 2.4. Seed the database
407+
### 2.5. Seed the database
386408

387409
Let's add some seed data to populate the database with sample users and posts.
388410

389411
Create a new file called `seed.ts` in the `prisma/` directory:
390412

391413
```typescript file=prisma/seed.ts
392-
//add-next-line
393-
import { PrismaClient, Prisma } from "../src/generated/prisma/client.js";
414+
import { PrismaClient, Prisma } from "../app/generated/prisma/client.js";
394415

395-
//add-next-line
396416
const prisma = new PrismaClient();
397417

398-
//add-start
399418
const userData: Prisma.UserCreateInput[] = [
400419
{
401420
name: "Alice",
@@ -428,28 +447,32 @@ const userData: Prisma.UserCreateInput[] = [
428447
},
429448
},
430449
];
431-
//add-end
432-
433-
//add-start
434450
export async function main() {
435451
for (const u of userData) {
436452
await prisma.user.create({ data: u });
437453
}
438454
}
439-
//add-end
440-
441-
//add-next-line
442455
main();
443456
```
444457

445-
Now, tell Prisma how to run this script by updating your `package.json`:
458+
Now, tell Prisma how to run this script by updating your `prisma.config.ts`:
446459

447-
```json file=package.json
460+
```ts file=prisma.config.ts
461+
import 'dotenv/config'
462+
import { defineConfig, env } from 'prisma/config';
463+
export default defineConfig({
464+
schema: 'prisma/schema.prisma',
465+
migrations: {
466+
path: 'prisma/migrations',
448467
//add-start
449-
"prisma": {
450-
"seed": "tsx prisma/seed.ts"
451-
}
468+
seed: `tsx prisma/seed.ts`,
452469
//add-end
470+
},
471+
engine: 'classic',
472+
datasource: {
473+
url: env('DATABASE_URL'),
474+
},
475+
});
453476
```
454477

455478
Run the seed script:

0 commit comments

Comments
 (0)