Skip to content

Commit 141ef26

Browse files
nurul3101aidankmcalister
authored andcommitted
(feat) Explicitly running prisma generate after migrate dev command and import updates (#7276)
1 parent 3619875 commit 141ef26

27 files changed

+160
-98
lines changed

content/800-guides/010-data-migration.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ Generate the migration:
137137
npx prisma migrate dev --name add-status-column
138138
```
139139

140+
Then generate Prisma Client:
141+
142+
```bash
143+
npx prisma generate
144+
```
145+
140146
## 3. Migrate the data
141147

142148
### 3.1. Create migration script
@@ -237,6 +243,12 @@ Create and run the final migration:
237243
npx prisma migrate dev --name drop-published-column
238244
```
239245

246+
Then generate Prisma Client:
247+
248+
```bash
249+
npx prisma generate
250+
```
251+
240252
## 5. Deploy to production
241253

242254
### 5.1. Set up deployment

content/800-guides/020-implementing-schema-changes.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ And generates a migration:
169169

170170
```terminal
171171
npx prisma migrate dev --name new-field
172+
npx prisma generate
172173
```
173174

174175
### 3.2. Developer B's changes
@@ -186,6 +187,7 @@ And generates a migration:
186187

187188
```terminal
188189
npx prisma migrate dev --name new-model
190+
npx prisma generate
189191
```
190192

191193
### 3.3. Merge changes
@@ -224,6 +226,7 @@ Run the migrate command:
224226

225227
```terminal
226228
npx prisma migrate dev
229+
npx prisma generate
227230
```
228231

229232
This will:

content/800-guides/080-turborepo.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Next, export the generated types and an instance of `PrismaClient` so it can use
364364
In the `packages/database` directory, create a `src` folder and add a `client.ts` file. This file will define an instance of `PrismaClient`:
365365

366366
```ts file=packages/database/src/client.ts
367-
import { PrismaClient } from "../generated/prisma";
367+
import { PrismaClient } from "../generated/prisma/client";
368368
import { PrismaPg } from '@prisma/adapter-pg';
369369

370370
const adapter = new PrismaPg({
@@ -384,8 +384,8 @@ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
384384
Then create an `index.ts` file in the `src` folder to re-export the generated prisma types and the `PrismaClient` instance:
385385

386386
```ts file=packages/database/src/index.ts
387-
export { prisma } from './client' // exports instance of prisma
388-
export * from "../generated/prisma" // exports generated types from prisma
387+
export { prisma } from './client' // exports instance of prisma
388+
export * from "../generated/prisma/client" // exports generated types from prisma
389389
```
390390

391391
Follow the [Just-in-Time packaging pattern](https://turbo.build/repo/docs/core-concepts/internal-packages#just-in-time-packages) and create an entrypoint to the package inside `packages/database/package.json`:

content/800-guides/090-nextjs.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,28 @@ export default defineConfig({
151151
});
152152
```
153153

154-
### 2.4. Configure the Prisma Client generator
154+
### 2.4. Run migrations and generate Prisma Client
155155

156-
Now, run the following command to create the database tables and generate the Prisma Client:
156+
Now, run the following command to create the database tables:
157157

158158
```terminal
159159
npx prisma migrate dev --name init
160160
```
161+
162+
Then generate Prisma Client:
163+
164+
```terminal
165+
npx prisma generate
166+
```
167+
161168
### 2.5. Seed the database
162169

163170
Add some seed data to populate the database with sample users and posts.
164171

165172
Create a new file called `seed.ts` in the `prisma/` directory:
166173

167174
```typescript file=prisma/seed.ts
168-
import { PrismaClient, Prisma } from "../app/generated/prisma";
175+
import { PrismaClient, Prisma } from "../app/generated/prisma/client";
169176
import { PrismaPg } from '@prisma/adapter-pg'
170177
import 'dotenv/config'
171178

@@ -285,7 +292,7 @@ Now, add the following code to your `lib/prisma.ts` file:
285292

286293
```typescript file=lib/prisma.ts showLineNumbers
287294
//add-start
288-
import { PrismaClient } from '../app/generated/prisma'
295+
import { PrismaClient } from '../app/generated/prisma/client'
289296
import { PrismaPg } from '@prisma/adapter-pg'
290297

291298
const globalForPrisma = global as unknown as {

content/800-guides/130-docker.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Add the following code to set up a basic Express server:
171171
```js file=index.js
172172
//add-start
173173
const express = require("express");
174-
const { PrismaClient } = require("./generated/prisma_client");
174+
const { PrismaClient } = require("./generated/prisma_client/client");
175175
const { PrismaPg } = require("@prisma/adapter-pg");
176176

177177
const adapter = new PrismaPg({
@@ -286,7 +286,13 @@ Run the migration to create the database schema:
286286
npx prisma migrate dev --name init
287287
```
288288

289-
This should generate a `migrations` folder in the `prisma` folder.
289+
Then generate Prisma Client:
290+
291+
```terminal
292+
npx prisma generate
293+
```
294+
295+
This should generate a `migrations` folder in the `prisma` folder and the Prisma Client in the `generated/prisma_client` directory.
290296

291297
### 2.4. Test the application
292298

content/800-guides/150-multiple-databases.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The `prisma@latest init --db` command:
9393

9494
- Connects your CLI to your [Prisma Data Platform](https://console.prisma.io) account. If you are not logged in or do not have an account, your browser will open to guide you through creating a new account or signing into your existing one.
9595
- Creates a `prisma` directory containing a `schema.prisma` file for your database models.
96-
- Creates a `.env` file with your `DATABASE_URL` (e.g., for Prisma Postgres it should have something similar to `DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI..."`).
96+
- Creates a `.env` file with your `DATABASE_URL` (e.g., `DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"`).
9797

9898
Rename the `prisma` folder to `prisma-user-database`:
9999

@@ -105,10 +105,10 @@ Edit your `.env` file to rename `DATABASE_URL` to `PPG_USER_DATABASE_URL`:
105105

106106
```text file=.env
107107
//delete-start
108-
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
108+
DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
109109
//delete-end
110110
//add-start
111-
PPG_USER_DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
111+
PPG_USER_DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
112112
//add-end
113113
```
114114

@@ -184,10 +184,10 @@ Rename the `DATABASE_URL` variable in `.env` to `PPG_POST_DATABASE_URL`:
184184

185185
```text file=.env
186186
//delete-start
187-
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
187+
DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
188188
//delete-end
189189
//add-start
190-
PPG_POST_DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
190+
PPG_POST_DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
191191
//add-end
192192
```
193193

@@ -287,7 +287,7 @@ In `lib/user-prisma-client.ts`, add the following code:
287287

288288
```ts file=lib/user-prisma-client.ts
289289
//add-start
290-
import { PrismaClient } from "../prisma-user-database/user-database-client-types";
290+
import { PrismaClient } from "../prisma-user-database/user-database-client-types/client";
291291
import { PrismaPg } from "@prisma/adapter-pg";
292292

293293
const adapter = new PrismaPg({
@@ -316,7 +316,7 @@ In `lib/post-prisma-client.ts`, add this code:
316316

317317
```ts file=lib/post-prisma-client.ts
318318
//add-start
319-
import { PrismaClient } from "../prisma-post-database/post-database-client-types";
319+
import { PrismaClient } from "../prisma-post-database/post-database-client-types/client";
320320
import { PrismaPg } from "@prisma/adapter-pg";
321321

322322
const adapter = new PrismaPg({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ Now, run the following command to create the database tables and generate the Pr
397397

398398
```terminal
399399
npx prisma migrate dev --name init
400+
npx prisma generate
400401
```
401402
### 2.5. Seed the database
402403

content/800-guides/170-react-router-7.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Now, run the following command to create the database tables and generate the Pr
136136

137137
```terminal
138138
npx prisma migrate dev --name init
139+
npx prisma generate
139140
```
140141
### 2.5. Seed the database
141142

content/800-guides/180-solid-start.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Now, run the following command to create the database tables and generate the Pr
157157

158158
```terminal
159159
npx prisma migrate dev --name init
160+
npx prisma generate
160161
```
161162
### 2.5. Seed the database
162163

content/800-guides/190-data-dog.mdx

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,7 @@ Run the following commands to install Prisma and a minimal TypeScript runner:
8080
npm install -D prisma tsx
8181
```
8282

83-
Then initialize Prisma:
84-
85-
:::note
86-
87-
You can use the `--db` flag to create a [new Prisma Postgres](/postgres) instance when initializing Prisma in your project.
88-
89-
:::
90-
91-
<TabbedContent code>
92-
<TabItem value="Prisma Postgres (recommended)">
93-
94-
<br />
83+
Then initialize Prisma with the `--db` flag to create a [new Prisma Postgres](/postgres) instance:
9584

9685
```terminal
9786
npx prisma init --db --output ../src/generated/prisma
@@ -102,43 +91,20 @@ npx prisma init --db --output ../src/generated/prisma
10291
You will be prompted to name your database and select the closest region. For clarity, choose a memorable name (e.g., `My Datadog Project`).
10392

10493
:::
105-
</TabItem>
106-
<TabItem value="Your own database">
107-
108-
```terminal
109-
npx prisma init --output ../src/generated/prisma
110-
```
111-
112-
</TabItem>
113-
</TabbedContent>
114-
11594

11695
This command does the following:
11796

118-
- Creates a `prisma` directory with a `schema.prisma` file.
97+
- Creates a `prisma` directory with a `schema.prisma` file.
11998
- Generates the Prisma Client in the `/src/generated/prisma` directory (as specified in the `--output` flag).
120-
- Creates a `.env` file at the project root with your database connection string (`DATABASE_URL`).
99+
- Creates a `.env` file at the project root with your database connection string (`DATABASE_URL`).
121100

122-
If you did not use the `--db` flag, replace the placeholder database URL in the `.env` file:
123-
124-
<TabbedContent code>
125-
<TabItem value="Prisma Postgres">
101+
The `.env` file should contain a standard connection string:
126102

127103
```bash file=.env
128-
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=..."
104+
# Placeholder url you have to replace
105+
DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
129106
```
130107

131-
</TabItem>
132-
<TabItem value="Your own database">
133-
134-
```bash file=.env
135-
# Placeholder url you have to replace
136-
DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
137-
```
138-
139-
</TabItem>
140-
</TabbedContent>
141-
142108
Install the driver adapter for PostgreSQL:
143109

144110
```terminal
@@ -289,7 +255,7 @@ Create a `src/client.ts` to hold your Prisma Client instantiation:
289255

290256
```ts file=src/client.ts
291257
import { tracer } from "./tracer";
292-
import { PrismaClient } from "./generated/prisma";
258+
import { PrismaClient } from "./generated/prisma/client";
293259
import { PrismaPg } from "@prisma/adapter-pg";
294260

295261
const adapter = new PrismaPg({

0 commit comments

Comments
 (0)