Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,71 @@ async function main() {
}
```

### Mapped enum values in generated TypeScript

:::warning

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 may need to use workarounds described below.

:::

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.

#### Before Prisma ORM v6

Given this Prisma schema:

```prisma
enum SuggestionStatus {
PENDING @map("pending")
ACCEPTED @map("accepted")
REJECTED @map("rejected")
}
```

In v6, the generated TypeScript enum would be:

```ts
export const SuggestionStatus = {
PENDING: 'PENDING',
ACCEPTED: 'ACCEPTED',
REJECTED: 'REJECTED'
} as const
```

#### After (v7)

In v7, the same schema generates:

```ts
export const SuggestionStatus = {
PENDING: 'pending',
ACCEPTED: 'accepted',
REJECTED: 'rejected'
} as const
```

This means that `SuggestionStatus.PENDING` now evaluates to `"pending"` instead of `"PENDING"`.

#### Migration steps

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.

**Temporary workaround** (until the bug is fixed):

Due to the current bug, you may need to use the schema name as a string literal instead of the generated enum value:

```ts
// This may cause a TypeScript error but works at runtime
await prisma.suggestion.create({
data: {
status: "PENDING" as any, // Use schema name, not mapped value
},
});
```

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.

### Client middleware has been removed

The client middleware API has been removed. If possible, use [Client Extensions](/orm/prisma-client/client-extensions).
Expand Down
58 changes: 58 additions & 0 deletions content/900-ai/prompts/prisma-7.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,63 @@ Your project will be migrated accordingly using the appropriate adapter.

---

## 11) Mapped Enum Breaking Change

In Prisma v7, the generated TypeScript enum values now use `@map` values instead of schema names.

### Example

Given this schema:
```prisma
enum SuggestionStatus {
PENDING @map("pending")
ACCEPTED @map("accepted")
REJECTED @map("rejected")
}
```

**v6 generated enum:**
```ts
export const SuggestionStatus = {
PENDING: 'PENDING',
ACCEPTED: 'ACCEPTED',
REJECTED: 'REJECTED'
} as const
```

**v7 generated enum:**
```ts
export const SuggestionStatus = {
PENDING: 'pending',
ACCEPTED: 'accepted',
REJECTED: 'rejected'
} as const
```

### Known Bug (as of v7.2.0)

⚠️ **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).

### Temporary Workarounds

1. **Use schema names as string literals** (causes TS error but works at runtime):
```ts
await prisma.suggestion.create({
data: {
status: "PENDING" as any, // Use schema name, not mapped value
},
});
```

2. **Remove `@map` from enum values** temporarily if you don't strictly need different database values.

### Migration Action

- Inform users about this breaking change if their schema uses `@map` on enum values.
- Warn about the current bug and suggest workarounds until it's fixed.

---

## Deliverables

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

````
Loading