Skip to content

Commit 5347a7c

Browse files
committed
docs(): add v7 migration guide
1 parent 3bf085d commit 5347a7c

File tree

2 files changed

+267
-0
lines changed

2 files changed

+267
-0
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
---
2+
title: 'Upgrade to Prisma ORM 7'
3+
metaTitle: 'Upgrade to Prisma ORM 7'
4+
metaDescription: 'Guides on how to upgrade to Prisma ORM 7'
5+
tocDepth: 3
6+
toc: true
7+
---
8+
9+
Prisma ORM v7 introduces **breaking changes** when you upgrade from an earlier Prisma ORM version. This guide explains how this upgrade might affect your application and gives instructions on how to handle any changes.
10+
11+
<details>
12+
<summary>Questions answered in this page</summary>
13+
14+
- What changed in Prisma 7?
15+
- How do I upgrade safely?
16+
- Which breaking changes affect my app?
17+
18+
</details>
19+
20+
## Upgrade the `prisma` and `@prisma/client` packages to v7
21+
22+
To upgrade to Prisma ORM v7 from an earlier version, you need to update both the `prisma` and `@prisma/client` packages:
23+
24+
<TabbedContent code>
25+
26+
<TabItem value="npm">
27+
28+
```terminal
29+
npm install @prisma/client@7
30+
npm install -D prisma@7
31+
```
32+
33+
</TabItem>
34+
35+
<TabItem value="yarn">
36+
37+
```terminal
38+
yarn up prisma@7 @prisma/client@7
39+
```
40+
41+
</TabItem>
42+
43+
<TabItem value="pnpm">
44+
45+
```terminal
46+
pnpm upgrade prisma@7 @prisma/client@7
47+
```
48+
49+
</TabItem>
50+
51+
<TabItem value="bun">
52+
53+
```terminal
54+
bun add @prisma/client@7
55+
bun add prisma@7 --dev
56+
```
57+
58+
</TabItem>
59+
60+
</TabbedContent>
61+
62+
:::danger
63+
64+
Before you upgrade, check each breaking change below to see how the upgrade might affect your application.
65+
66+
:::
67+
68+
## Breaking changes
69+
70+
This section gives an overview of breaking changes in Prisma ORM v7.
71+
72+
### Minimum supported Node.js & TypeScript versions
73+
74+
| | Minimum Version | Recommended |
75+
|------------|-----------------|-------------|
76+
| Node | 20.19.0 | 22.x |
77+
| TypeScript | 5.4.0 | 5.9.x |
78+
79+
### ESM Support
80+
Prisma ORM now ships as an ES module, module format supported in Bun, Deno, and Node. Set the
81+
`type` field in your `package.json` to `module`
82+
83+
```json
84+
{
85+
"type": "module",
86+
"scripts": {...},
87+
}
88+
```
89+
90+
If you are using TypeScript, you need to configure your `tsconfig.json` to be able to consume ES modules
91+
92+
```json
93+
{
94+
"compilerOptions": {
95+
"module": "ESNext",
96+
"moduleResolution": "node",
97+
"target": "ES2023",
98+
"strict": true,
99+
"esModuleInterop": true
100+
}
101+
}
102+
```
103+
104+
105+
### Prisma Schema Changes
106+
107+
The older `prisma-client-js` provider will be removed in future releases of Prisma ORM. Upgrade to
108+
the new `prisma-client` provider which uses the new Rust-free client. This will give you faster
109+
queries, smaller bundle size, and require less system resources when deployed to your server.
110+
111+
112+
#### Before
113+
```prisma
114+
generator client {
115+
provider = "prisma-client-js"
116+
engineType = "binary"
117+
}
118+
```
119+
120+
#### After
121+
```prisma
122+
generator client {
123+
provider = "prisma-client"
124+
}
125+
```
126+
127+
Additionally other fields such as `url`, `directUrl`, and `shadowDatabaseUrl` in the `datasource` block are deprecated and now part of the [Prisma Config](/orm/reference/prisma-config-reference)
128+
129+
130+
### Driver Adapters and Client Instantiation
131+
The way to create a new Prisma Client has changed to require a driver adapter for all databases.
132+
This change aligns with the move to make the main Prisma Clinet as lean and open as possible. For
133+
instance, if you are using Prisma Postgres, you now need the `@prisma/adapter-pg` adapter. This also
134+
means the signature for creating a new Prisma Client has changed slightly:
135+
136+
#### Before
137+
138+
```ts
139+
import { PrismaClient } from '@prisma/client';
140+
const prisma = new PrismaClient({
141+
datasources: {
142+
db: { url: process.env.DATABASE_URL },
143+
},
144+
datasourceUrl: process.env.DATABASE_URL,
145+
});
146+
```
147+
148+
#### After
149+
150+
```ts
151+
import { PrismaClient } from './generated/prisma/client.js';
152+
import { PrismaPg } from '@prisma/adapter-pg';
153+
154+
const adapter = new PrismaPg({
155+
connectionString: process.env.DATABASE_URL
156+
});
157+
const prisma = new PrismaClient({ adapter });
158+
```
159+
160+
If you are using SQLite, you can use the `@prisma/adapter-better-sqlite3`:
161+
162+
```ts
163+
import { PrismaClient } from './generated/prisma/client.js';
164+
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
165+
166+
const adapter = new PrismaBetterSQLite3({
167+
url: process.env.DATABASE_URL || 'file:./dev.db'
168+
})
169+
170+
export const prisma = new PrismaClient({ adapter })
171+
```
172+
173+
### Explicit loading of Environment Variables
174+
In Prisma ORM 7.0.0, environment variables are not loaded by default. Instead developers need to
175+
explicitly load the variables when calling the `prisma` CLI. Libraries like [`dotenv`](https://github.com/motdotla/dotenv) can be used to manage loading environment variables by reading the appropriate `.env` file.
176+
177+
178+
<TabbedContent code>
179+
180+
<TabItem value="npm">
181+
182+
```terminal
183+
npm install dotenv
184+
```
185+
186+
</TabItem>
187+
188+
<TabItem value="yarn">
189+
190+
```terminal
191+
yarn add dotenv
192+
```
193+
194+
</TabItem>
195+
196+
<TabItem value="pnpm">
197+
198+
```terminal
199+
pnpm add dotenv
200+
```
201+
202+
</TabItem>
203+
204+
</TabbedContent>
205+
206+
For bun users, no action is required as bun will automatically load `.env` files.
207+
208+
### Prisma Config is now used to configure the Prisma CLI
209+
210+
Prisma Config is now the default place for configuring how the Prisma CLI interacts with your
211+
database. You now configure your database URL, schema location, migration output, and custom seed
212+
scripts.
213+
214+
```ts
215+
import 'dotenv/config'
216+
import { defineConfig, env } from 'prisma/config'
217+
218+
export default defineConfig({
219+
// the main entry for your scheam
220+
schema: 'prisma/schema.prisma',
221+
// where migrations should be generated
222+
// what script to run for "prisma db seed"
223+
migrations: {
224+
path: 'prisma/migrations',
225+
seed: 'tsx prisma/seed.ts',
226+
},
227+
// The database URL
228+
datasource: {
229+
// Type Safe env() helper
230+
// Does not replace the need for dotenv
231+
url: env('DATABASE_URL'),
232+
},
233+
})
234+
```
235+
236+
237+
238+
### Metrics has been removed from the Client extensions
239+
240+
The Metrics preview feature was deprecated in [Prisma ORM 6.14.0](https://github.com/prisma/prisma/releases/tag/6.14.0) and has been removed for Prisma ORM 7.0.0.
241+
If you need this feature, use the underlying driver adapter for the database you are using and
242+
incorporate Client extensions to expose that information.
243+
244+
### Client Middleware has been removed
245+
246+
The client middleware API has been removed in favor of using
247+
[Extensions](orm/prisma-client/client-extensions).
248+
249+
```ts
250+
// ❌ Old (removed)
251+
prisma.$use(async (params, next) => {
252+
// middleware logic
253+
return next(params)
254+
})
255+
// ✅ New (use extensions)
256+
const prisma = new PrismaClient().$extends({
257+
query: {
258+
user: {
259+
async findMany({ args, query }) {
260+
// extension logic
261+
return query(args)
262+
}
263+
}
264+
}
265+
})
266+
```

content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ To upgrade to the latest version of Prisma ORM:
2424

2525
### Prisma ORM 2 and onwards
2626

27+
- [Upgrade to Prisma ORM 7](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-7)
2728
- [Upgrade to Prisma ORM 6](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-6)
2829
- [Upgrade to Prisma ORM 5](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-5)
2930
- [Upgrade to Prisma ORM 4](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-4)

0 commit comments

Comments
 (0)