You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/200-orm/100-prisma-schema/20-data-model/50-database-mapping.mdx
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,38 @@ enum Type {
74
74
}
75
75
```
76
76
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
+
exportconst Status = {
96
+
PENDING: 'pending',
97
+
APPROVED: 'approved'
98
+
} asconst
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
+
77
109
## Constraint and index names
78
110
79
111
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.)
Copy file name to clipboardExpand all lines: content/200-orm/500-reference/100-prisma-schema-reference.mdx
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2722,6 +2722,23 @@ enum Role {
2722
2722
}
2723
2723
```
2724
2724
2725
+
In Prisma ORM v7 and later, the generated TypeScript enum uses the mapped values:
2726
+
2727
+
```ts
2728
+
exportconst Role = {
2729
+
ADMIN: 'admin',
2730
+
CUSTOMER: 'CUSTOMER'
2731
+
} asconst
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
+
2725
2742
### `@@map`
2726
2743
2727
2744
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.
Copy file name to clipboardExpand all lines: content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/400-upgrading-to-prisma-7.mdx
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -342,6 +342,89 @@ async function main() {
342
342
}
343
343
```
344
344
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
+
exportconst SuggestionStatus = {
371
+
PENDING: 'PENDING',
372
+
ACCEPTED: 'ACCEPTED',
373
+
REJECTED: 'REJECTED'
374
+
} asconst
375
+
```
376
+
377
+
#### After Prisma ORM v7
378
+
379
+
In v7, the same schema generates:
380
+
381
+
```ts
382
+
exportconst SuggestionStatus = {
383
+
PENDING: 'pending',
384
+
ACCEPTED: 'accepted',
385
+
REJECTED: 'rejected'
386
+
} asconst
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
+
awaitprisma.suggestion.create({
402
+
data: {
403
+
status: "PENDING"asany, // 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
+
345
428
### Client middleware has been removed
346
429
347
430
The client middleware API has been removed. If possible, use [Client Extensions](/orm/prisma-client/client-extensions).
Copy file name to clipboardExpand all lines: content/900-ai/prompts/prisma-7.mdx
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -360,6 +360,79 @@ prisma migrate diff \
360
360
361
361
---
362
362
363
+
## 11) Mapped Enum Breaking Change
364
+
365
+
In Prisma v7, the generated TypeScript enum values now use `@map` values instead of schema names.
366
+
367
+
### Example
368
+
369
+
Given this schema:
370
+
```prisma
371
+
enum SuggestionStatus {
372
+
PENDING @map("pending")
373
+
ACCEPTED @map("accepted")
374
+
REJECTED @map("rejected")
375
+
}
376
+
```
377
+
378
+
**v6 generated enum:**
379
+
```ts
380
+
exportconst SuggestionStatus = {
381
+
PENDING: 'PENDING',
382
+
ACCEPTED: 'ACCEPTED',
383
+
REJECTED: 'REJECTED'
384
+
} asconst
385
+
```
386
+
387
+
**v7 generated enum:**
388
+
```ts
389
+
exportconst SuggestionStatus = {
390
+
PENDING: 'pending',
391
+
ACCEPTED: 'accepted',
392
+
REJECTED: 'rejected'
393
+
} asconst
394
+
```
395
+
396
+
### Known Bug (as of v7.2.0)
397
+
398
+
⚠️ **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).
399
+
400
+
### Temporary Workarounds
401
+
402
+
1.**Use schema names as string literals** (causes TS error but works at runtime):
403
+
```ts
404
+
awaitprisma.suggestion.create({
405
+
data: {
406
+
status: "PENDING"asany, // Use schema name, not mapped value
407
+
},
408
+
});
409
+
```
410
+
411
+
2.**Remove `@map` from enum values** temporarily if you don't strictly need different database values:
412
+
```prisma
413
+
// Before: with @map directives
414
+
enum SuggestionStatus {
415
+
PENDING @map("pending")
416
+
ACCEPTED @map("accepted")
417
+
REJECTED @map("rejected")
418
+
}
419
+
420
+
// After: without @map directives
421
+
enum SuggestionStatus {
422
+
PENDING
423
+
ACCEPTED
424
+
REJECTED
425
+
}
426
+
```
427
+
With this change, both the schema names and the database values will be `PENDING`, `ACCEPTED`, and `REJECTED`.
428
+
429
+
### Migration Action
430
+
431
+
- Inform users about this breaking change if their schema uses `@map` on enum values.
432
+
- Warn about the current bug and suggest workarounds until it's fixed.
433
+
434
+
---
435
+
363
436
## Deliverables
364
437
365
438
- A short **CHANGELOG** summary in the PR body:
@@ -371,5 +444,6 @@ prisma migrate diff \
371
444
- Seed script updates
372
445
- No automatic removal of Accelerate
373
446
- CLI flag changes (`--schema` and `--url` removal from `db execute`, `migrate diff` option changes)
0 commit comments