Repository navigation
TML-2855: enum field defaults by member — @default(Low) renders DEFAULT 'low' - #808
Conversation
📝 WalkthroughWalkthroughThis PR implements enum member default lowering across PSL and TypeScript contract authoring, demonstrates the feature with a Priority enum default migration in the demo app, and updates contract artifacts, runtime code, and tests to support enum-backed field defaults. ChangesEnum2 Member Defaults and Priority Demo
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
fc93a32 to
47e9d9c
Compare
4f4fcb3 to
105e548
Compare
Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
TS DSL: `field.namedType(EnumHandle)` now returns `EnumScalarFieldBuilder`
whose `.default()` accepts only the handle's member value union
(`Values[number]`). A non-member literal is a compile-time error.
`defaultSql` is overridden to `never` on the enum builder (function defaults
on enum2 fields are not allowed). Lowering emits `{ kind: 'literal', value }`.
PSL: `@default(MemberName)` on an enum2 field resolves the bare identifier
against the enum's member names and lowers to the member's value as a literal
default. Non-member identifiers, quoted raw values, and function defaults each
emit a dedicated diagnostic (`PSL_ENUM2_UNKNOWN_DEFAULT_MEMBER` /
`PSL_ENUM2_DEFAULT_MUST_BE_MEMBER_NAME`). `enum2Handles` is threaded from
`buildModelNodeFromPsl` into `collectResolvedFields` via a new optional field
on `CollectResolvedFieldsInput`. Non-enum and native-enum `@default` lowering
is unchanged. The PSL↔TS parity test is extended with a defaulted field;
storageHash equality is asserted on both authoring paths.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Add @default(Low) to the demo's priority Priority field in both PSL and TS no-emit contracts; re-emit contract.json / contract.d.ts (storage diff: priority column gains "default":{"kind":"literal","value":"low"}, storageHash recomputes to 372f890); create migration 20260610T2216_set_priority_default with a single setDefault op (ALTER TABLE post ALTER COLUMN priority SET DEFAULT 'low'); fix pre-existing pgvector contract-space hash drift (3b5e09f → 8ac1bfb, metadata-only change from tml-2882 emissions); add integration test proving an insert omitting priority reads back 'low'. Sweep: test:packages green (800 files / 10352 tests); demo typecheck clean; fixtures:check zero-diff outside deliberate demo changes; lint:deps clean; no new bare casts. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Member defaults via `@default(EnumType.Member)` are additive and opt-in. Demo regeneration only. No consumer migration path needed; the cutover carries user-facing docs. Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
105e548 to
f469ed1
Compare
wmadden
left a comment
There was a problem hiding this comment.
Ensure this feature is demonstrated in example app code in both the emit and no-emit paths. Not just in tests. Otherwise looks good
Co-Authored-By: Will Madden <[email protected]> Signed-off-by: Will Madden <[email protected]>
Adds `enum-default-demo` to both main.ts (emitted contract) and main-no-emit.ts (inline TS contract). Each command inserts a Post without supplying `priority` — typed-optional because the contract records @default(Low) / .default(Priority.members.Low) — reads the row back, and confirms the database supplied 'low'. Cleanup runs at the end of each demo. Also updates the emitted contract.d.ts artifacts (src/prisma and migrations) to include the typed enum block now generated by the current emitter. Co-Authored-By: Will Madden <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Done (03df382). Added |
The previous regeneration ran against a stale dist carrying the TML-2885 emitter, injecting the typed domain enum block this branch cannot produce. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/prisma-next-demo/src/queries/enum-default-demo-no-emit.ts`:
- Around line 12-48: Wrap the main demo flow in enumDefaultDemoNoEmit in a try {
... } finally { ... } so cleanup always runs: perform the inserts, select and
assertions inside the try block and move both delete calls (the
sql.post.delete() for demoPostId and sql.user.delete() for demoUserId) into the
finally block so runtime.execute(...) is invoked to remove demoPostId and
demoUserId even if an error occurs; keep existing checks (e.g., the row/null
check) inside the try.
In `@packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts`:
- Around line 417-438: The current lowering uses
enum2Handles?.get(field.typeName) which misses named-type aliases; update the
resolution so if enum2Handles.get(field.typeName) is undefined you resolve the
named type descriptor (namedTypeDescriptors?.get(field.typeName) or similar) to
find the underlying enum2 name/descriptor and then look up enum2Handles by that
underlying name before deciding between lowerEnum2DefaultForField and
lowerDefaultForField; keep the same call sites (lowerEnum2DefaultForField,
lowerDefaultForField) and pass the same parameters once you have the resolved
enumHandle so alias-typed fields like PriorityAlias will correctly use the enum2
path.
In `@skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md`:
- Around line 178-186: Update the PSL examples and prose to use the bare enum
member form for defaults: replace usages of `@default`(EnumType.Member) and
`@default`(Priority.Low) with `@default`(Low) (and any other member examples) and
change the generic placeholder `@default`(<EnumType>.<Member>) to
`@default`(<Member>); ensure the text clarifies that PSL enum defaults use only
the member identifier (not the enum name) so examples and placeholder match the
actual authoring surface referenced by the doc.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 0a5002ae-17bc-4bfc-9b2a-dc06d4bb4daf
⛔ Files ignored due to path filters (2)
projects/enums-as-domain-concept/slices/enum-member-defaults/plan.mdis excluded by!projects/**projects/enums-as-domain-concept/slices/enum-member-defaults/spec.mdis excluded by!projects/**
📒 Files selected for processing (26)
examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/contract.prismaexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/end-contract.jsonexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/migration.jsonexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/migration.tsexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/ops.jsonexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/start-contract.d.tsexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/start-contract.jsonexamples/prisma-next-demo/migrations/pgvector/20260601T0000_install_vector_extension/migration.jsonexamples/prisma-next-demo/migrations/pgvector/contract.jsonexamples/prisma-next-demo/migrations/pgvector/refs/head.jsonexamples/prisma-next-demo/prisma/contract.tsexamples/prisma-next-demo/src/main-no-emit.tsexamples/prisma-next-demo/src/main.tsexamples/prisma-next-demo/src/prisma/contract.d.tsexamples/prisma-next-demo/src/prisma/contract.jsonexamples/prisma-next-demo/src/prisma/contract.prismaexamples/prisma-next-demo/src/queries/enum-default-demo-no-emit.tsexamples/prisma-next-demo/src/queries/enum-default-demo.tsexamples/prisma-next-demo/test/enum-surface.integration.test.tspackages/2-sql/2-authoring/contract-psl/src/interpreter.tspackages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.tspackages/2-sql/2-authoring/contract-psl/test/interpreter.enum2.test.tspackages/2-sql/2-authoring/contract-ts/src/contract-dsl.tspackages/2-sql/2-authoring/contract-ts/test/enum-type.member-defaults.test.tsskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
| export async function enumDefaultDemoNoEmit(runtime: Runtime): Promise<void> { | ||
| await runtime.execute( | ||
| sql.user.insert([{ id: demoUserId, email: '[email protected]', kind: 'user' }]).build(), | ||
| ); | ||
|
|
||
| // `priority` is intentionally omitted — the field is typed-optional here | ||
| // because the TS contract declares `.default(Priority.members.Low)`. | ||
| await runtime.execute( | ||
| sql.post.insert([{ id: demoPostId, title: 'Enum-default demo', userId: demoUserId }]).build(), | ||
| ); | ||
|
|
||
| const rows = await runtime.execute( | ||
| sql.post | ||
| .select('id', 'priority') | ||
| .where((f, fns) => fns.eq(f.id, demoPostId)) | ||
| .build(), | ||
| ); | ||
| const row = rows[0]; | ||
| if (!row) throw new Error('Demo post not found after insert'); | ||
|
|
||
| console.log(`priority read back from DB: ${row.priority}`); | ||
| console.log( | ||
| `Expected 'low' (the .default(Priority.members.Low) value): ${row.priority === 'low'}`, | ||
| ); | ||
|
|
||
| await runtime.execute( | ||
| sql.post | ||
| .delete() | ||
| .where((f, fns) => fns.eq(f.id, demoPostId)) | ||
| .build(), | ||
| ); | ||
| await runtime.execute( | ||
| sql.user | ||
| .delete() | ||
| .where((f, fns) => fns.eq(f.id, demoUserId)) | ||
| .build(), | ||
| ); |
There was a problem hiding this comment.
Root cause: cleanup is not guaranteed when using fixed demo IDs.
Both demo implementations only delete inserted rows on the happy path. Any mid-flow error can leave records behind and make reruns fail with ID collisions. Consolidate both to the same try { ... } finally { cleanup } structure.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/prisma-next-demo/src/queries/enum-default-demo-no-emit.ts` around
lines 12 - 48, Wrap the main demo flow in enumDefaultDemoNoEmit in a try { ... }
finally { ... } so cleanup always runs: perform the inserts, select and
assertions inside the try block and move both delete calls (the
sql.post.delete() for demoPostId and sql.user.delete() for demoUserId) into the
finally block so runtime.execute(...) is invoked to remove demoPostId and
demoUserId even if an error occurs; keep existing checks (e.g., the row/null
check) inside the try.
| const enum2Handle = enum2Handles?.get(field.typeName); | ||
| const loweredDefault: LoweredFieldDefault = defaultAttribute | ||
| ? enum2Handle | ||
| ? lowerEnum2DefaultForField({ | ||
| modelName: model.name, | ||
| fieldName: field.name, | ||
| defaultAttribute, | ||
| enumHandle: enum2Handle, | ||
| sourceId, | ||
| diagnostics, | ||
| }) | ||
| : lowerDefaultForField({ | ||
| modelName: model.name, | ||
| fieldName: field.name, | ||
| defaultAttribute, | ||
| columnDescriptor: descriptor, | ||
| generatorDescriptorById, | ||
| sourceId, | ||
| defaultFunctionRegistry, | ||
| diagnostics, | ||
| }) | ||
| : {}; |
There was a problem hiding this comment.
Handle enum2 aliases when lowering member defaults.
enum2Handles?.get(field.typeName) only matches fields typed with the enum2’s original name. Named types already resolve enum2-backed descriptors through namedTypeDescriptors, so a schema like type PriorityAlias = Priority plus priority PriorityAlias @default(Low) will fall back to the generic scalar-default path and reject a valid enum member default. Resolve the underlying enum2 handle through named-type aliases too.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts` around
lines 417 - 438, The current lowering uses enum2Handles?.get(field.typeName)
which misses named-type aliases; update the resolution so if
enum2Handles.get(field.typeName) is undefined you resolve the named type
descriptor (namedTypeDescriptors?.get(field.typeName) or similar) to find the
underlying enum2 name/descriptor and then look up enum2Handles by that
underlying name before deciding between lowerEnum2DefaultForField and
lowerDefaultForField; keep the same call sites (lowerEnum2DefaultForField,
lowerDefaultForField) and pass the same parameters once you have the resolved
enumHandle so alias-typed fields like PriorityAlias will correctly use the enum2
path.
| <!-- | ||
| TML-2855: member defaults via `@default(member)` (PR #808). The PSL interpreter and | ||
| contract-ts authoring surface now resolve `@default(EnumType.Member)` to a | ||
| `{ kind: 'literal', value: '<dbValue>' }` default. The demo `priority` field gains | ||
| `@default(Priority.Low)` and a new migration (`20260610T2216_set_priority_default`) | ||
| is emitted. Additive and opt-in: only fields that declare `@default(<EnumType>.<Member>)` | ||
| are affected; no existing contract changes shape. No consumer action required; the | ||
| cutover (TML-2853) will carry the user-facing docs. | ||
| --> |
There was a problem hiding this comment.
Correct the PSL syntax examples to match the actual authoring surface.
The documentation uses @default(EnumType.Member) and @default(Priority.Low) notation, but the actual PSL syntax for enum member defaults is a bare member identifier: @default(Low), not @default(Priority.Low). The enum name prefix is not part of the PSL surface.
📝 Suggested correction
<!--
TML-2855: member defaults via `@default(member)` (PR `#808`). The PSL interpreter and
-contract-ts authoring surface now resolve `@default(EnumType.Member)` to a
+contract-ts authoring surface now resolve `@default(Member)` (bare member identifier in PSL) to a
`{ kind: 'literal', value: '<dbValue>' }` default. The demo `priority` field gains
-`@default(Priority.Low)` and a new migration (`20260610T2216_set_priority_default`)
+`@default(Low)` and a new migration (`20260610T2216_set_priority_default`)
is emitted. Additive and opt-in: only fields that declare `@default(<EnumType>.<Member>)`
are affected; no existing contract changes shape. No consumer action required; the
cutover (TML-2853) will carry the user-facing docs.
-->Note: Line 183's generic placeholder @default(<EnumType>.<Member>) should also be @default(<Member>) to match PSL syntax, though as a placeholder in prose it may be acceptable if clarified that it refers to member name only.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md`
around lines 178 - 186, Update the PSL examples and prose to use the bare enum
member form for defaults: replace usages of `@default`(EnumType.Member) and
`@default`(Priority.Low) with `@default`(Low) (and any other member examples) and
change the generic placeholder `@default`(<EnumType>.<Member>) to
`@default`(<Member>); ensure the text clarifies that PSL enum defaults use only
the member identifier (not the enum name) so examples and placeholder match the
actual authoring surface referenced by the doc.
…gh emit (prisma#809) ## Linked issue Refs [TML-2885](https://linear.app/prisma-company/issue/TML-2885). **Was stacked on prisma#808 → prisma#805** — both now merged; this PR targets `main` directly (rebased, four commits). With TML-2855, completes the cutover's (TML-2853) parity prerequisites. ## At a glance The emitted `contract.d.ts` now types the domain `enum` block, so `db.enums` is literal-typed **through the emitted contract** — closing the R6 emit-parity gap found in prisma#805's review: ```ts // before (emitted path): runtime correct, types collapsed db.enums.public.Priority.values // JsonValue[] db.enums.public.Priority.members.High // JsonValue // after db.enums.public.Priority.values // readonly ['low', 'high', 'urgent'] db.enums.public.Priority.members.High // 'high' ``` ```ts // emitted contract.d.ts — the public namespace gains: readonly enum: { readonly Priority: { readonly codecId: 'pg/text@1'; readonly members: readonly [ { readonly name: 'Low'; readonly value: 'low' }, { readonly name: 'High'; readonly value: 'high' }, { readonly name: 'Urgent'; readonly value: 'urgent' } ]; }; }; ``` ## Decision One change site: the emitter renders the per-namespace domain `enum` block with literal member tuples (order preserved — it's semantic). The **existing** accessor type chain (`NamespaceEnumAccessors` / `NamespacedEnums` in `enum-accessor.ts`) already extracts literal `values`/`members` from exactly this shape, so it is untouched — as are the runtime and the TML-2852 field narrowing. `contract.json` and every hash are byte-identical: this is a types-only emission change. The acceptance evidence is deletion: the demo's `getPriorityEnumFromEmit()` workaround and its `blindCast`s — whose reason strings documented exactly this gap — are gone; every consumer reads `db.enums.public.Priority` directly, cast-free (net −4 `blindCast` sites). ## Reviewer notes - **Non-vacuity is compile-level:** without the emitted enum block, `db.enums.public.Priority` does not exist at the type level, so the demo type tests fail to compile (verified by deleting the block and watching six files fail; restored cleanly). Stronger than a runtime assert. - **One genuinely new `blindCast`** in [generate-contract-dts.ts](packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts) (`ns.enum`), byte-identical in idiom to the two pre-existing sibling casts (`ns.models`, `ns.valueObjects`) it sits beside. - **A real stack regression was caught and fixed during this slice:** TML-2882's `aad4e15b3` made `blockAttributes` required on `PslExtensionBlock`; a cli test fixture predated it. Earlier "full typecheck green" runs were stale-dist false greens. Fixed on the base branch (`53680da2e` on prisma#805) and the stack rebased. - The JSON→TS literal rendering reuses the TML-2852 D4 helpers (`serializeValue`/`serializeObjectKey`) — no duplication. ## Behavior changes & evidence - **The emitter renders the domain enum block** — [generate-contract-dts.ts](packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts); evidence: [emitter.integration.test.ts](packages/1-framework/3-tooling/emitter/test/emitter.integration.test.ts) (string codec, int-codec bare-number literals, quoted non-identifier member keys, enum-less namespaces emit no block; unbound-namespace coverage folded in). - **`db.enums` is literal-typed through emit, cast-free in the demo** — [get-posts-by-priority.ts](examples/prisma-next-demo/src/queries/get-posts-by-priority.ts) (workaround deleted), [demo-dx.types.test.ts](examples/prisma-next-demo/test/demo-dx.types.test.ts) (literal `members.High` / `values` through the emitted artifacts). - **Types-only:** no `.json` file changes; four `.d.ts` files regenerate with only the additive enum block. ## Testing performed - `pnpm test:packages` — green on final HEAD (one adapter-postgres DB-infra timeout, diff-unreachable) - `pnpm typecheck` — green incl. `@prisma-next/cli` against fresh dist (see reviewer note on the fixed stack regression) - `pnpm fixtures:check` — clean (full re-emit against fresh dist, no drift) - `pnpm lint:deps` — clean ## Skill update n/a — types-only emission change; the user-facing `db.enums` surface was documented with TML-2852, and the transitional-keyword docs policy (skill lands at cutover) carries the rest. ## Follow-ups - TML-2853 (cutover) — parity prerequisites now complete once this stack merges. ## Alternatives considered - **Narrowing at the accessor instead of emitting the block** (parameterize `EnumAccessor` per call site). Rejected: the accessor chain was already built to extract from the typed contract shape; emitting the shape fixes every consumer at once and keeps "the `.d.ts` is the contract" honest. - **Emitting only the value tuples (not full member pairs).** Rejected: `members.<Name>` needs the name→value literal pairs; the full tuple is what `EnumEntryMembers` consumes, and it matches the runtime JSON one-for-one. ## Checklist - [x] All commits are signed off (`git commit -s`) per the [DCO](../CONTRIBUTING.md#developer-certificate-of-origin-dco). The DCO status check will block merge if any commit is missing a `Signed-off-by:` trailer. - [x] I read [CONTRIBUTING.md](../CONTRIBUTING.md) and the change is scoped to one logical concern. - [x] Tests are updated (or `n/a` if the change is doc-only / refactor with no behavioural delta). - [x] The PR title is in `TML-NNNN: <sentence-case title>` form (Linear ticket prefix + concise title naming the concrete deliverable). See `.claude/skills/create-pr/SKILL.md` for the full convention. - [x] The **Skill update** section above is filled in (or stated `n/a — internal only`). --------- Signed-off-by: Will Madden <[email protected]> Co-authored-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Linked issue
Refs TML-2855.
Was stacked on #805 (TML-2882) — now merged; this PR targets
maindirectly (rebased, four commits).With TML-2885, the last parity prerequisite before the cutover (TML-2853).
At a glance
An enum field declares its default by naming a member, on both authoring surfaces, and it lands as an ordinary literal:
enum2 Priority { @@type("pg/text@1") Low = "low" High = "high" Urgent = "urgent" } model Post { priority Priority @default(Low) // names a member — not the raw string "low" }Before this PR,
.default()on an enum-typed field accepted any literal, and PSL@defaulthad no member awareness.Decision
Member-to-literal resolution happens at lowering, per authoring surface — there is no new
ColumnDefaultvariant and no machinery below the lowering. The storage column carries the resolved literal ({ "kind": "literal", "value": "low" }), so the storage plane stays plannable in isolation per the directional invariant settled on #805 (domain may reference storage; storage may never reference domain). TheenumMembervariant the original ticket described predates that correction and was never shipped; this PR supersedes it (see the ticket's 2026-06-10 respec comment and project spec §9).Reviewer notes
EnumScalarFieldBuilder.default()narrows to the handle's member value union (Handle['values'][number]); the package typecheck passes with the@ts-expect-errordirectives present, so each rejected literal genuinely errors.defaultSqlis a type error (and runtime throw) on enum builders.fe9ce0f53on the base branch canonicalized emptytypeParamsout of emitted contracts, but the demo's copied pgvector space was never re-emitted and still carried the old shape + hash. Running the migration tooling surfaced it; this PR re-emits it (byte-identical to the pgvector package's own contract). Tree-wide there are zero"typeParams":{}survivors now..default()narrowing is lost if.nullable()/.id()is chained before it (base builder methods return the base type). Recorded in the review ledger; closes when nullable-with-default enum fields are needed."default": "low"as shorthand; the persisted shape is the existing object form ({"kind":"literal","value":"low"}), identical to every other literal default on the wire (e.g.task.status).How it fits together
EnumTypeHandleoverload ofnamedTypeFieldreturns anEnumScalarFieldBuilderwhose.default()accepts only the member value union and lowers to the existing literal default.enum2,@default(<identifier>)resolves the member name to its value (literal default); non-member identifiers, quoted raw values, and function defaults are span-accurate diagnostics. Non-enum and native-enum@defaultlowering is untouched.buildColumnDefaultSql, verification all see an ordinary literal default.@default(Low)in the PSL schema (mirrored in the TS no-emit contract), re-emitted artifacts, migration20260610T2216_set_priority_default(a singlesetDefaultop), and an integration test inserting a post withoutpriorityand reading back'low'— including the type-level proof that the insert payload'sprioritybecame optional.Behavior changes & evidence
.default()is members-only on enum fields — contract-dsl.ts; evidence: enum-type.member-defaults.test.ts (string + int codecs, positive/negative type tests, lowering shape).@default(member)resolves on enum2 fields, with three rejection diagnostics — psl-field-resolution.ts; evidence: interpreter.enum2.test.ts, including the strict PSL/TS parity test (deep-equal +storageHash) extended with a defaulted field.priorityinsert reading back'low'; evidence: enum-surface.integration.test.ts.Testing performed
pnpm test:packages— 800 files / 10,352 tests green on final HEADpnpm typecheckgreen for all packages this diff can reach (recurring stale-dist environment artifacts in unrelated packages adjudicated in review, same shape as on the base branch)pnpm fixtures:check— clean outside the demo's deliberate changespnpm lint:deps— cleanSkill update
n/a — the
@default(member)surface rides the transitionalenum2keyword, which is retired at the cutover; user-facing docs land with the cutover rename (same policy as #805).Follow-ups
.default()narrowing through.nullable()/.id()chains when nullable-with-default enum fields land.db.enums(the other cutover prerequisite).Alternatives considered
enumMemberColumnDefaultvariant recording the member in storage (the original ticket design). Rejected by the 2026-06-10 directional-invariant settlement: it is a storage → domain reference, and storage must be plannable in isolation. The resolved literal carries everything DDL needs; the authored source names the member, so intent is recoverable by re-emit.@default("low")). Rejected (per the ticket): severs the domain link, can't be membership-checked at authoring time; it is an explicit diagnostic now.Checklist
git commit -s) per the DCO. The DCO status check will block merge if any commit is missing aSigned-off-by:trailer.n/aif the change is doc-only / refactor with no behavioural delta).TML-NNNN: <sentence-case title>form (Linear ticket prefix + concise title naming the concrete deliverable). See.claude/skills/create-pr/SKILL.mdfor the full convention.n/a — internal only).Summary by CodeRabbit
New Features
@default(EnumMember)syntax. This allows enum fields to be optional on insert operations, with the database automatically applying the specified default value when omitted.Chores