Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

TML-2885: emit typed domain enum block — db.enums literal-typed through emit - #809

Merged
wmadden merged 4 commits into
mainfrom
tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed
Jun 11, 2026
Merged

wmadden merged 4 commits into
mainfrom
tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2885.
Was stacked on #808 → #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 #805's review:

// 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'
// 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 blindCasts — 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 (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 TML-2882: transitional enum2 block makes the new enum PSL-authorable #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; evidence: 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 (workaround deleted), 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

  • All commits are signed off (git commit -s) per the DCO. The DCO status check will block merge if any commit is missing a Signed-off-by: trailer.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated (or n/a if the change is doc-only / refactor with no behavioural delta).
  • 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.
  • The Skill update section above is filled in (or stated n/a — internal only).

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 10, 2026 23:07
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@wmadden-electric, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ad74b791-ae87-4724-9275-08e3f6a3fe62

📥 Commits

Reviewing files that changed from the base of the PR and between dcc2613 and 9d1a89e.

⛔ Files ignored due to path filters (2)
  • projects/enums-as-domain-concept/slices/emit-typed-domain-enums/plan.md is excluded by !projects/**
  • projects/enums-as-domain-concept/slices/emit-typed-domain-enums/spec.md is excluded by !projects/**
📒 Files selected for processing (16)
  • examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/start-contract.d.ts
  • examples/prisma-next-demo/scripts/seed.ts
  • examples/prisma-next-demo/src/main.ts
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • examples/prisma-next-demo/src/queries/get-posts-by-priority.ts
  • examples/prisma-next-demo/test/demo-dx.types.test.ts
  • examples/prisma-next-demo/test/repositories.integration.test.ts
  • examples/prisma-next-demo/test/sql-dsl.integration.test.ts
  • packages/1-framework/0-foundation/contract/src/enum-accessor.ts
  • packages/1-framework/0-foundation/contract/src/exports/enum-accessor.ts
  • packages/1-framework/0-foundation/contract/test/enum-accessor.test.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.integration.test.ts
  • skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@809

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@809

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@809

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@809

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@809

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@809

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@809

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@809

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@809

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@809

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@809

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@809

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@809

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@809

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@809

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@809

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@809

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@809

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@809

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@809

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@809

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@809

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@809

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@809

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@809

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@809

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@809

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@809

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@809

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@809

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@809

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@809

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@809

prisma-next

npm i https://pkg.pr.new/prisma-next@809

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@809

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@809

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@809

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@809

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@809

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@809

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@809

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@809

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@809

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@809

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@809

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@809

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@809

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@809

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@809

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@809

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@809

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@809

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@809

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@809

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@809

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@809

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@809

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@809

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@809

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@809

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@809

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@809

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@809

commit: 9d1a89e

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 153.94 KB (+0.02% 🔺)
postgres / emit 121.29 KB (+0.02% 🔺)
mongo / no-emit 76.8 KB (0%)
mongo / emit 70.96 KB (0%)
cf-worker / no-emit 182.91 KB (0%)
cf-worker / emit 147.02 KB (0%)

@wmadden-electric
wmadden-electric force-pushed the tml-2855-slice-enum-member-defaults-defaultadmin-renders-default branch 2 times, most recently from 105e548 to f469ed1 Compare June 11, 2026 09:17
@wmadden-electric
wmadden-electric force-pushed the tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed branch 3 times, most recently from f6c8e21 to ab6cf65 Compare June 11, 2026 09:45

@wmadden wmadden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad first attempt but you retained more of the indirect logic than necessary

Comment thread examples/prisma-next-demo/src/main.ts Resolved
@wmadden-electric
wmadden-electric force-pushed the tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed branch from ab6cf65 to 187fa8b Compare June 11, 2026 10:37
@wmadden-electric

Copy link
Copy Markdown
Contributor Author

Added to ContractEnumAccessor:

  • has(v: JsonValue): v is ValueUnion — type predicate (was boolean)
  • hasName(name: string): name is NameUnion — new
  • EnumValues<A> / EnumMemberNames<A> type helpers exported from @prisma-next/contract/enum-accessor

Demo indirection deleted across all five threads.

Base automatically changed from tml-2855-slice-enum-member-defaults-defaultadmin-renders-default to main June 11, 2026 10:39
wmadden and others added 4 commits June 11, 2026 12:39
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]>
…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]>
@wmadden-electric
wmadden-electric force-pushed the tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed branch from 187fa8b to 9d1a89e Compare June 11, 2026 10:39
@wmadden
wmadden added this pull request to the merge queue Jun 11, 2026
Merged via the queue into main with commit ef38144 Jun 11, 2026
20 checks passed
@wmadden
wmadden deleted the tml-2885-slice-emit-typed-domain-enum-block-dbenums-literal-typed branch June 11, 2026 11:21
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jun 15, 2026
…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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants