Skip to content

@default on a field of a @map-ed enum emits the enum name as the column default #2868

Description

@ymc9

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    runtimeZenStack runtime related

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions