Summary
When an enum member has a @map-ed value and a field uses it as the default, db push emits the enum name rather than the mapped database value as the column default. On PostgreSQL table creation fails.
Repro
enum PostStatus {
DRAFT @map('draft')
ACTIVE @map('active')
}
model User {
id Int @id @default(autoincrement())
status PostStatus @default(DRAFT)
}
Pushing this schema to PostgreSQL fails with:
invalid input value for enum "PostStatus": "DRAFT"
The generated DDL contains DEFAULT 'DRAFT' while the PostgreSQL enum type only has the values 'draft' and 'active'.
Where
packages/orm/src/client/helpers/schema-db-pusher.ts, the col.defaultTo(fieldDef.default) branch. The enum type itself is created with the mapped values (see the @map handling a few lines above in the same file), but the default is passed through unmapped.
Found while probing mapped-enum behavior for #2807.
Summary
When an enum member has a
@map-ed value and a field uses it as the default,db pushemits the enum name rather than the mapped database value as the column default. On PostgreSQL table creation fails.Repro
Pushing this schema to PostgreSQL fails with:
The generated DDL contains
DEFAULT 'DRAFT'while the PostgreSQL enum type only has the values'draft'and'active'.Where
packages/orm/src/client/helpers/schema-db-pusher.ts, thecol.defaultTo(fieldDef.default)branch. The enum type itself is created with the mapped values (see the@maphandling a few lines above in the same file), but the default is passed through unmapped.Found while probing mapped-enum behavior for #2807.