Skip to content

Commit e748d8d

Browse files
docs: add mapped enums breaking change to Prisma 7 upgrade guide (#7401)
* docs: add mapped enums breaking change to Prisma 7 upgrade guide * Update content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/400-upgrading-to-prisma-7.mdx Co-authored-by: Ankur Datta <[email protected]> * Update content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/400-upgrading-to-prisma-7.mdx Co-authored-by: Ankur Datta <[email protected]> * Apply suggestion from @ankur-arch Co-authored-by: Ankur Datta <[email protected]> * Apply suggestion from @ankur-arch Co-authored-by: Ankur Datta <[email protected]> * Apply suggestion from @ankur-arch Co-authored-by: Ankur Datta <[email protected]> * update content with example * update other pages for @Map --------- Co-authored-by: Ankur Datta <[email protected]>
1 parent 414da5c commit e748d8d

File tree

4 files changed

+206
-0
lines changed

4 files changed

+206
-0
lines changed

content/200-orm/100-prisma-schema/20-data-model/50-database-mapping.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,38 @@ enum Type {
7474
}
7575
```
7676

77+
In this example:
78+
- `@@map("comment_source_enum")` maps the enum name `Type` to `comment_source_enum` in the database
79+
- `@map("comment_twitter")` maps the enum value `Twitter` to `comment_twitter` in the database
80+
81+
#### Effect on generated TypeScript (Prisma ORM v7+)
82+
83+
In Prisma ORM v7 and later, when you use `@map` on enum values, the generated TypeScript enum uses the **mapped values** instead of the schema names:
84+
85+
```prisma
86+
enum Status {
87+
PENDING @map("pending")
88+
APPROVED @map("approved")
89+
}
90+
```
91+
92+
This generates the following TypeScript:
93+
94+
```ts
95+
export const Status = {
96+
PENDING: 'pending',
97+
APPROVED: 'approved'
98+
} as const
99+
```
100+
101+
This means `Status.PENDING` evaluates to `"pending"`, not `"PENDING"`.
102+
103+
:::warning
104+
105+
There is currently a known bug in Prisma ORM v7 where using mapped enum values with Prisma Client operations causes runtime errors. See the [Prisma 7 upgrade guide](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-7#mapped-enum-values-in-generated-typescript) for workarounds and details.
106+
107+
:::
108+
77109
## Constraint and index names
78110

79111
You can optionally use the `map` argument to explicitly define the **underlying constraint and index names** in the Prisma schema for the attributes [`@id`](/orm/reference/prisma-schema-reference#id), [`@@id`](/orm/reference/prisma-schema-reference#id-1), [`@unique`](/orm/reference/prisma-schema-reference#unique), [`@@unique`](/orm/reference/prisma-schema-reference#unique-1), [`@@index`](/orm/reference/prisma-schema-reference#index) and [`@relation`](/orm/reference/prisma-schema-reference#relation). (This is available in Prisma ORM version [2.29.0](https://github.com/prisma/prisma/releases/tag/2.29.0) and later.)

content/200-orm/500-reference/100-prisma-schema-reference.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,23 @@ enum Role {
27222722
}
27232723
```
27242724

2725+
In Prisma ORM v7 and later, the generated TypeScript enum uses the mapped values:
2726+
2727+
```ts
2728+
export const Role = {
2729+
ADMIN: 'admin',
2730+
CUSTOMER: 'CUSTOMER'
2731+
} as const
2732+
```
2733+
2734+
This means `Role.ADMIN` evaluates to `"admin"`, not `"ADMIN"`.
2735+
2736+
:::warning
2737+
2738+
There is currently a known bug in Prisma ORM v7 where using mapped enum values with Prisma Client operations causes runtime errors. See the [Prisma 7 upgrade guide](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-7#mapped-enum-values-in-generated-typescript) for workarounds and details.
2739+
2740+
:::
2741+
27252742
### `@@map`
27262743

27272744
Maps the Prisma schema model name to a table (relational databases) or collection (MongoDB) with a different name, or an enum name to a different underlying enum in the database. If you do not use `@@map`, the model name matches the table (relational databases) or collection (MongoDB) name exactly.

content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/400-upgrading-to-prisma-7.mdx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,89 @@ async function main() {
342342
}
343343
```
344344

345+
### Mapped enum values in generated TypeScript
346+
347+
:::warning
348+
349+
There is currently a known bug where using mapped enum values with Prisma Client operations (like `create`, `update`, etc.) causes runtime errors. The generated TypeScript types expect the mapped values, but the Prisma Client engine expects the schema names. This issue is being tracked in [GitHub issue #28591](https://github.com/prisma/prisma/issues/28591). Until this is fixed, you need to use workarounds described below.
350+
351+
:::
352+
353+
In Prisma ORM v7, the generated TypeScript enum values now use the `@map` values instead of the schema names. This is a breaking change from v6.
354+
355+
#### Before Prisma ORM v6
356+
357+
Given this Prisma schema:
358+
359+
```prisma
360+
enum SuggestionStatus {
361+
PENDING @map("pending")
362+
ACCEPTED @map("accepted")
363+
REJECTED @map("rejected")
364+
}
365+
```
366+
367+
In v6, the generated TypeScript enum would be:
368+
369+
```ts
370+
export const SuggestionStatus = {
371+
PENDING: 'PENDING',
372+
ACCEPTED: 'ACCEPTED',
373+
REJECTED: 'REJECTED'
374+
} as const
375+
```
376+
377+
#### After Prisma ORM v7
378+
379+
In v7, the same schema generates:
380+
381+
```ts
382+
export const SuggestionStatus = {
383+
PENDING: 'pending',
384+
ACCEPTED: 'accepted',
385+
REJECTED: 'rejected'
386+
} as const
387+
```
388+
389+
This means that `SuggestionStatus.PENDING` now evaluates to `"pending"` instead of `"PENDING"`.
390+
391+
#### Migration steps
392+
393+
If you're using mapped enums, you'll need to update any code that relies on the enum values being the schema names rather than the mapped values.
394+
395+
##### Temporary workaround
396+
397+
Until we resolve [the open issue](https://github.com/prisma/prisma/issues/28591), you need to use the schema name as a string literal instead of the generated enum value:
398+
399+
```ts
400+
// This may cause a TypeScript error but works at runtime
401+
await prisma.suggestion.create({
402+
data: {
403+
status: "PENDING" as any, // Use schema name, not mapped value
404+
},
405+
});
406+
```
407+
408+
Alternatively, you can temporarily remove the `@map` directives from your enum values if you don't strictly need the database values to differ from the schema names:
409+
410+
```prisma
411+
// Before: with @map directives
412+
enum SuggestionStatus {
413+
PENDING @map("pending")
414+
ACCEPTED @map("accepted")
415+
REJECTED @map("rejected")
416+
}
417+
418+
// After: without @map directives
419+
enum SuggestionStatus {
420+
PENDING
421+
ACCEPTED
422+
REJECTED
423+
}
424+
```
425+
426+
With this change, both the schema names and the database values will be `PENDING`, `ACCEPTED`, and `REJECTED`, and the generated TypeScript enum will work correctly with Prisma Client operations.
427+
345428
### Client middleware has been removed
346429

347430
The client middleware API has been removed. If possible, use [Client Extensions](/orm/prisma-client/client-extensions).

content/900-ai/prompts/prisma-7.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,79 @@ Your project will be migrated accordingly using the appropriate adapter.
302302

303303
---
304304

305+
## 11) Mapped Enum Breaking Change
306+
307+
In Prisma v7, the generated TypeScript enum values now use `@map` values instead of schema names.
308+
309+
### Example
310+
311+
Given this schema:
312+
```prisma
313+
enum SuggestionStatus {
314+
PENDING @map("pending")
315+
ACCEPTED @map("accepted")
316+
REJECTED @map("rejected")
317+
}
318+
```
319+
320+
**v6 generated enum:**
321+
```ts
322+
export const SuggestionStatus = {
323+
PENDING: 'PENDING',
324+
ACCEPTED: 'ACCEPTED',
325+
REJECTED: 'REJECTED'
326+
} as const
327+
```
328+
329+
**v7 generated enum:**
330+
```ts
331+
export const SuggestionStatus = {
332+
PENDING: 'pending',
333+
ACCEPTED: 'accepted',
334+
REJECTED: 'rejected'
335+
} as const
336+
```
337+
338+
### Known Bug (as of v7.2.0)
339+
340+
⚠️ **There is a known bug** where using mapped enum values with Prisma Client operations causes runtime errors. The TypeScript types expect mapped values, but the engine expects schema names. Track this at [GitHub #28591](https://github.com/prisma/prisma/issues/28591).
341+
342+
### Temporary Workarounds
343+
344+
1. **Use schema names as string literals** (causes TS error but works at runtime):
345+
```ts
346+
await prisma.suggestion.create({
347+
data: {
348+
status: "PENDING" as any, // Use schema name, not mapped value
349+
},
350+
});
351+
```
352+
353+
2. **Remove `@map` from enum values** temporarily if you don't strictly need different database values:
354+
```prisma
355+
// Before: with @map directives
356+
enum SuggestionStatus {
357+
PENDING @map("pending")
358+
ACCEPTED @map("accepted")
359+
REJECTED @map("rejected")
360+
}
361+
362+
// After: without @map directives
363+
enum SuggestionStatus {
364+
PENDING
365+
ACCEPTED
366+
REJECTED
367+
}
368+
```
369+
With this change, both the schema names and the database values will be `PENDING`, `ACCEPTED`, and `REJECTED`.
370+
371+
### Migration Action
372+
373+
- Inform users about this breaking change if their schema uses `@map` on enum values.
374+
- Warn about the current bug and suggest workarounds until it's fixed.
375+
376+
---
377+
305378
## Deliverables
306379

307380
- A short **CHANGELOG** summary in the PR body:
@@ -312,5 +385,6 @@ Your project will be migrated accordingly using the appropriate adapter.
312385
- ESM/TS config updates
313386
- Seed script updates
314387
- No automatic removal of Accelerate
388+
- Mapped enum breaking change warning (if applicable)
315389

316390
````

0 commit comments

Comments
 (0)