Skip to content

Commit 26fe072

Browse files
Merge branch 'main' into dr-6653-cli-prisma-db-execute-does-not-accept-schema-anymore
2 parents 2d83ba7 + e748d8d commit 26fe072

5 files changed

Lines changed: 207 additions & 0 deletions

File tree

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/500-reference/375-supported-databases.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ An asterisk (\*) indicates that the version number is not relevant; either all v
3434
| PostgreSQL | 15 |
3535
| PostgreSQL | 16 |
3636
| PostgreSQL | 17 |
37+
| PostgreSQL | 18 |
3738
| SQLite | \* |
3839

3940
Note that a fixed version of SQLite is shipped with every Prisma ORM release.

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
@@ -360,6 +360,79 @@ prisma migrate diff \
360360

361361
---
362362

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+
export const SuggestionStatus = {
381+
PENDING: 'PENDING',
382+
ACCEPTED: 'ACCEPTED',
383+
REJECTED: 'REJECTED'
384+
} as const
385+
```
386+
387+
**v7 generated enum:**
388+
```ts
389+
export const SuggestionStatus = {
390+
PENDING: 'pending',
391+
ACCEPTED: 'accepted',
392+
REJECTED: 'rejected'
393+
} as const
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+
await prisma.suggestion.create({
405+
data: {
406+
status: "PENDING" as any, // 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+
363436
## Deliverables
364437

365438
- A short **CHANGELOG** summary in the PR body:
@@ -371,5 +444,6 @@ prisma migrate diff \
371444
- Seed script updates
372445
- No automatic removal of Accelerate
373446
- CLI flag changes (`--schema` and `--url` removal from `db execute`, `migrate diff` option changes)
447+
- Mapped enum breaking change warning (if applicable)
374448

375449
````

0 commit comments

Comments
 (0)