`@default` on a field of a `@map`-ed enum emits the enum name as the column default
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, typescript
Research direction
Read packages/orm/src/client/helpers/schema-db-pusher.ts, focusing on the col.defaultTo(fieldDef.default) branch and the nearby @map handling. Find and run the existing tests for schema pushing; done when a mapped enum default uses its mapped database value in the generated DDL and pushing the repro schema to PostgreSQL succeeds.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 157
- Avg merge
- 11h 42m
- Merged PRs (30d)
- 20
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from zenstackhq/zenstack
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
zenstackhq/zenstack#2873 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
zenstackhq/zenstack#2694 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
zenstackhq/zenstack#2659 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
zenstackhq/zenstack#2542 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
zenstackhq/zenstack#2296 ·
Maintainers usually reply within 1 day
All issues in zenstackhq/zenstack
Similar issues
-
Add: YRF Music NepalOpenstreams:add
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
walletbeat/walletbeat#1558 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
hawk-digital-environments/HAWKI#438 ·
Maintainers usually reply within 1 day
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
GiganticMinecraft/seichi-portal-frontend#1165 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day