Repository navigation
TML-2885: emit typed domain enum block — db.enums literal-typed through emit - #809
Conversation
|
Warning Review limit reached
More reviews will be available in 3 minutes and 58 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (16)
✨ Finishing Touches🧪 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 📦
|
105e548 to
f469ed1
Compare
f6c8e21 to
ab6cf65
Compare
wmadden
left a comment
There was a problem hiding this comment.
Not a bad first attempt but you retained more of the indirect logic than necessary
ab6cf65 to
187fa8b
Compare
|
Added to
Demo indirection deleted across all five threads. |
Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
The emitter now renders a `readonly enum` block in each namespace type
for namespaces that declare domain enums. Each enum entry carries a
literal `codecId` and an ordered `readonly members` tuple of
`{ name; value }` pairs with literal types.
The existing `NamespaceEnumAccessors` / `NamespacedEnums` accessor chain
resolves `db.enums.<ns>.<Name>.values` / `.members` to literals through
the emitted contract — no accessor changes were needed.
The demo's `getPriorityEnumFromEmit()` + `priorityValue()` blindCasts are
deleted in favour of direct `db.enums.public.Priority` consumption. Net
blindCast count decreases by 4.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…numValues helper; drop demo indirection - ContractEnumAccessor.has() now a type predicate (v is ValueUnion) - ContractEnumAccessor.hasName() added — narrows to member-name union - EnumValues<A> and EnumMemberNames<A> helper types exported from @prisma-next/contract/enum-accessor - EnumAccessor base interface gains hasName() - Demo: seed.ts, integration tests — drop PriorityMemberName alias + priorityValue() helper; direct .members.X access - Demo: get-posts-by-priority.ts — param typed as EnumValues<typeof Priority> (value, not name) - Demo: main.ts enum-priority-filter — replace inline isPriorityMember predicate with priority.hasName() Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
187fa8b to
9d1a89e
Compare
…ry (prisma#817) ## Linked issue Refs [TML-2853](https://linear.app/prisma/issue/TML-2853) — cutover: `enum` becomes the domain concept; delete the native machinery. Prerequisite: TML-2885 (prisma#809) — typed domain enum block in `contract.d.ts`. --- ## At a glance Before 0.14 (native form, now deleted): ```prisma enum user_type { admin user } ``` After 0.14 (domain enum, what `enum` means now): ```prisma enum user_type { @@type("pg/text@1") admin = "admin" user = "user" } ``` Same change in the TS authoring API: ```ts // Before — deleted import { enumType } from '@prisma-next/adapter-postgres/column-types'; const Role = enumType('Role', ['USER', 'ADMIN']); // After — `enumType` + `member` from the contract-builder import { enumType, member } from '@prisma-next/postgres/contract-builder'; const pgText = { codecId: 'pg/text@1', nativeType: 'text' } as const; const Role = enumType('Role', pgText, member('USER', 'USER'), member('ADMIN', 'ADMIN')); ``` The emitted contract is identical to what `enum2` produced in 0.13. --- ## Reviewer notes - **Big diff, but mostly deletion.** The net stat is −6936 lines across 244 files, driven by the native-enum machinery removal. The meaningful additions are in the PSL interpreter, the TS contract-builder, the converting migration, and the upgrade instructions. Spot-check `packages/2-sql/2-authoring/contract-psl/src/interpreter.ts`, `packages/3-targets/3-targets/postgres/src/core/migrations/planner-strategies.ts`, and the upgrade instructions in `skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md`. - **The example-app migration history is by-design regenerated.** `fixtures:check` deterministically recomputes all migration artifact hashes after an emitter-touching change; the single changed file (`20260422T0720_initial/migration.json`) is the canonical output of that process, not a hand-merged hash. Commit `f585e1506` captures it. - **`lint:casts` delta is −34 vs merge-base.** The removed enum codec and planner paths carried most of the existing `blindCast` / `castAs` calls. No new casts introduced. - **`enum2` keyword is retired, not converted.** Any schema with `enum2` blocks will produce a diagnostic after 0.14 until the author renames to `enum`. The upgrade instructions explain the rename. - **`rebase --onto` conflict resolution.** The rebase had 5 conflict files, all enum-adjacent or migration-hash. In `planner-strategies.ts` the conflict was between main's DDL-AST-pioneer version of `buildColumnSpec` (which still referenced `PostgresEnumStorageEntry`) and D2's deletion of that type. Resolution: kept the DDL-pioneer logic, dropped the `PostgresEnumStorageEntry` type from the cast (replaced with plain `StorageTypeInstance`). In `codec-ids.ts` the same `PG_UUID_CODEC_ID` constant appeared in both sides — kept the main HEAD addition; dropped `PG_ENUM_CODEC_ID` (gone in D2). - **Mongo + typing mechanism are NOT in this PR.** R10 (Mongo enums) and the emit-path typing fix are follow-up work. The `plan.md` notes this explicitly. --- ## Decision This PR delivers two things: 1. **Keyword flip.** The `enum` PSL keyword and the `enumType` / `enumColumn` TS helpers now author the domain enum (text-class column + CHECK constraint). The transitional `enum2` keyword introduced in TML-2880 is retired; `enum` is the only form. The `postgres/contract-builder` is the canonical author import; the old native `enumType`/`enumColumn` from `adapter-postgres/column-types` are deleted. 2. **Native-enum machinery deletion.** The entire native Postgres enum stack is gone: `PostgresEnumType`, `postgres-enum-storage-entry.ts`, the `pg/enum@1` codec, migration ops `CreateEnumTypeCall` / `AddEnumValuesCall` / `DropEnumTypeCall` / `RenameTypeCall`, `enum-planning.ts`, `operations/enums.ts`, `nativeEnumPlanCallStrategy`, native `pg_enum` introspection, and the `postgresAuthoringEntityTypes.enum` contribution. The cast ratchet drops by 34 (`lint:casts` current=1203 vs merge-base=1237). See [spec § What this replaces](projects/enums-as-domain-concept/spec.md#what-this-replaces-deletion) for the deletion inventory. --- ## How it fits together 1. **PSL parser — enum block removed.** `parsePslDocument` no longer recognizes `enum` as a namespace-level block declaration. The parser no longer accumulates `PslEnum` nodes; `parseEnumBlock`, `flatPslEnums`, `PslEnum`/`PslEnumValue` types, and related diagnostics are deleted. The `enum` keyword previously produced a native-enum entity via the Postgres authoring contribution; it now has no parser recognition at all. File: `packages/1-framework/2-authoring/psl-parser/src/parser.ts`. 2. **PSL interpreter — domain enum lowering.** The interpreter now treats a PSL `enum` block as a domain-enum block (same as `enum2`). `processEnumDeclarations` is gone; `processEnumTypeBlocks` (already present for `enum2`) handles both keywords after D1 aliases `enum` to `enum2` in the interpreter's dispatch. File: `packages/2-sql/2-authoring/contract-psl/src/interpreter.ts`. 3. **TS contract-builder — native helpers deleted.** `enumType(name, values[])` and `enumColumn` from `@prisma-next/adapter-postgres/column-types` are deleted. The canonical authoring path is `enumType(name, codecRef, ...members)` + `member(name, value)` from `@prisma-next/postgres/contract-builder`, returning an `EnumTypeHandle` under the contract's `enums` key. `defineContract` already accepted `enums`; no shape change. File: `packages/2-sql/2-authoring/contract-ts/src/contract-builder.ts`. 4. **Planner — native enum strategies gone.** `nativeEnumPlanCallStrategy`, `CreateEnumTypeCall`, `AddEnumValuesCall`, `DropEnumTypeCall`, `RenameTypeCall`, and `enum-planning.ts` are deleted. The planner only handles the value-set + CHECK realization, which was already in place from the domain-enum slices. Files: `packages/3-targets/3-targets/postgres/src/core/migrations/planner-strategies.ts`, `op-factory-call.ts`, `operations/enums.ts` (deleted). 5. **Introspection diagnostic re-wired.** The control adapter no longer queries `pg_enum`. The native-enum introspection path is replaced with a diagnostic that tells users native enum types cannot be adopted (they need the converting migration). File: `packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts`. 6. **Converting migration in the demo.** `examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/migration.ts` is the converting migration for the demo's `priority` column: ALTER to text USING cast, add the value-set CHECK, DROP the native type. The `migration-replay` test in `prisma-next-demo` replays all migrations and confirms the database lands on the domain-enum shape. File: `examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/migration.ts`. --- ## Behavior changes & evidence - **`enum` keyword in PSL now authors a domain enum, not a native Postgres enum.** A schema with `enum Foo { @@type("pg/text@1") A = "a" }` emits a domain `enum` entry and a `valueSet` storage entry; columns typed `Foo` get a CHECK constraint in migration DDL. The PSL parity test confirms emit matches the TS-authored contract: `test/integration/test/authoring/parity/core-surface/contract.ts`, `expected.contract.json`. - **`enum2` keyword is retired.** The interpreter no longer recognizes `enum2`; schemas using it get a `PSL_UNKNOWN_BLOCK` diagnostic. Evidence: `packages/1-framework/2-authoring/psl-parser/test/parser-enum.test.ts` (renamed from `parser-enum2.test.ts`). - **`pg/enum@1` codec and native-enum column type are gone.** `PG_ENUM_CODEC_ID` is removed from `codec-ids.ts`; `PG_ENUM_CODEC_ID` references in tests are replaced with value-set variants. Evidence: `packages/3-targets/3-targets/postgres/test/codecs.test.ts`. - **Migration planner no longer emits native enum DDL.** `CreateEnumTypeCall`, `AddEnumValuesCall`, `DropEnumTypeCall`, and `RenameTypeCall` are deleted. The planner emits `AddCheckConstraintCall` / `DropCheckConstraintCall` for value-set changes instead. Evidence: `test/integration/test/cross-package/postgres-issue-planner.test.ts`. - **Demo's converting migration replays cleanly.** The `prisma-next-demo` migration chain (57/57 tests passing incl. `migration-integrity` + `migration-replay`) proves the converting migration round-trips the database from the native-enum shape to the domain-enum shape. --- ## Compatibility / migration / risk This is a **breaking change** in 0.14. Any project with PSL `enum` blocks (without `@@type(...)`) or TS `enumType` from `adapter-postgres/column-types` will fail to compile after upgrade. The upgrade instructions at `skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md` and `skills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/instructions.md` cover: - Converting PSL schema syntax (add `@@type(...)`, replace member names with `= "value"` form, drop `@map`, rename `enum2` to `enum`). - Replacing the TS authoring API (`enumType` + `member` from `postgres/contract-builder`). - Writing the one-time converting migration for databases that already carry a native `CREATE TYPE` enum. Databases that already carry native Postgres enum types need a one-time converting migration before they can use the new `enum` form. `contract infer` will refuse native enum types and name them in its diagnostic. --- ## Verification ``` pnpm build # 66/66 tasks, clean pnpm typecheck # 138/138 pnpm fixtures:check # exit 0; 1 migration artifact regenerated + committed pnpm lint:deps # no violations pnpm lint:casts # current=1203 merge-base=1237 delta=−34 pnpm --filter prisma-next-demo test # 57/57 (migration-integrity + migration-replay included) ``` --- ## Follow-ups - **R10 — Mongo domain enums.** Not in this PR. Independent of the SQL cutover; Mongo has no native type to replace. Follow-up ticket. - **Emit-path typing fix.** The `db.enums.<Name>` accessor type-widens to `JsonValue` in the emitted-path accessor surface (the same escape noted in the spec for TML-2852 D4). Follow-up after the emit-typed-block slice lands. --- ## Alternatives considered - **Keep `enum` as a native-enum keyword and retire it in a future version.** We chose to flip `enum` immediately because the native semantics are being deleted in this PR anyway — there is nothing to keep backward-compatible. A phased deprecation would extend the window during which the codebase contains dead native-enum infrastructure. - **Keep `pg/enum@1` codec for projects that want native enums.** The spec explicitly positions native Postgres enum types as a non-goal for this project. They can return as an alternative storage realization later; keeping the codec now would leave dead infra in place and add ambiguity about whether native enums are still a first-class surface. - **Keep `enum2` as an alias indefinitely.** Rejected. The `enum` keyword carrying the domain semantics is the whole point of the cutover. A permanent alias for the same form would just be noise in the grammar. --- ## Checklist - [x] All commits are signed off (`git commit -s`) per the DCO. `git log origin/main..HEAD --format='%(trailers:key=Signed-off-by)'` shows `Signed-off-by:` trailers on all 15 commits. - [x] I read CONTRIBUTING.md and the change is scoped to one logical concern. - [x] Tests are updated (PSL parser tests, planner tests, parity tests, demo migration tests). - [x] The PR title is in `TML-NNNN: <sentence-case title>` form. - [x] **Skill update:** `skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md` and `skills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/instructions.md` document the enum-becomes-domain-concept migration. `skills/prisma-next-contract/SKILL.md` updated to reflect the new `enumType`/`member` API. --------- Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]> Co-authored-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Linked issue
Refs TML-2885.
Was stacked on #808 → #805 — both now merged; this PR targets
maindirectly (rebased, four commits).With TML-2855, completes the cutover's (TML-2853) parity prerequisites.
At a glance
The emitted
contract.d.tsnow types the domainenumblock, sodb.enumsis literal-typed through the emitted contract — closing the R6 emit-parity gap found in #805's review:Decision
One change site: the emitter renders the per-namespace domain
enumblock with literal member tuples (order preserved — it's semantic). The existing accessor type chain (NamespaceEnumAccessors/NamespacedEnumsinenum-accessor.ts) already extracts literalvalues/membersfrom exactly this shape, so it is untouched — as are the runtime and the TML-2852 field narrowing.contract.jsonand every hash are byte-identical: this is a types-only emission change.The acceptance evidence is deletion: the demo's
getPriorityEnumFromEmit()workaround and itsblindCasts — whose reason strings documented exactly this gap — are gone; every consumer readsdb.enums.public.Prioritydirectly, cast-free (net −4blindCastsites).Reviewer notes
db.enums.public.Prioritydoes 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.blindCastin generate-contract-dts.ts (ns.enum), byte-identical in idiom to the two pre-existing sibling casts (ns.models,ns.valueObjects) it sits beside.aad4e15b3madeblockAttributesrequired onPslExtensionBlock; a cli test fixture predated it. Earlier "full typecheck green" runs were stale-dist false greens. Fixed on the base branch (53680da2eon TML-2882: transitional enum2 block makes the new enum PSL-authorable #805) and the stack rebased.serializeValue/serializeObjectKey) — no duplication.Behavior changes & evidence
db.enumsis literal-typed through emit, cast-free in the demo — get-posts-by-priority.ts (workaround deleted), demo-dx.types.test.ts (literalmembers.High/valuesthrough the emitted artifacts)..jsonfile changes; four.d.tsfiles 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/cliagainst 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— cleanSkill update
n/a — types-only emission change; the user-facing
db.enumssurface was documented with TML-2852, and the transitional-keyword docs policy (skill lands at cutover) carries the rest.Follow-ups
Alternatives considered
EnumAccessorper 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.tsis the contract" honest.members.<Name>needs the name→value literal pairs; the full tuple is whatEnumEntryMembersconsumes, and it matches the runtime JSON one-for-one.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).