Repository navigation
Data types and casts: every written default has a type its column casts from (ADR 254) - #30350
Merged
Merged
Conversation
…eclare
A literal column default has a literal type: string, number, boolean, or json. A codec descriptor declares the literal types its columns are compatible with, with read and write functions only where the codec JSON form differs from the literal value. PSL writes a literal as a plain scalar or as a tagged literal such as json`{}`; the sql tag writes a raw SQL expression instead. Codecs never see PSL syntax.
ADR 253 replaces the PSL half of ADR 184. The remove-dbgenerated project spec amends D9 and D10 to match, the plan runs slice B after slice A, and the slice B spec is marked superseded until it is rewritten.
Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The literal types are cut where the codecs stored JSON forms are cut: string, boolean, int, float, bigint, decimal, and json. Each produces the value shape the codecs that name it already accept in decodeJson, so a codec descriptor carries a list of names and no read or write functions, and the rules for whole numbers, decimal canonicalisation, and digit preservation are written once per literal type. Records as open, for discussion before implementation, that a plain number scalar names no literal type of its own: 42 is an int literal on an Int column, a bigint literal on a BigInt column, and a decimal literal on a Decimal column, decided by what the column codec declares. The numeric literal types are not implemented until that is settled. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…aults A self-contained brief for an implementer with no prior context: what the repository terms mean, what ADR 253 decides, the full inventory of which literal type every codec names, the order of work, what to reuse from the withdrawn attempt, the documentation to update, and the definition of done. Section 1 marks the one blocked decision: a plain number scalar names no literal type of its own, so the numeric literal types are not implemented until Will has been asked which of the three recorded answers to take. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… worktree/literal-types-column-defaults-852235
…ypes by size Replaces the withdrawn encodePsl/decodePsl design. Records the shaping decisions: a written number takes its literal type from its own size and precision, codecs name every type they accept and coerce inside decodeJson, and a vector default is a list literal. Lists the corrections found when verifying the implementation brief against the code. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A written literal now has a type of its own, classified from what was written rather than from the column it lands on: readLiteral turns a source-independent WrittenLiteral into a Literal, isCompatible checks it against a codec's declarations by name, describeDeclarations words that for a diagnostic, and writeLiteral runs the path backwards to produce the literal's source text. Numbers are classified by size with BigInt comparison, so 42 is an i8 everywhere and 100000000000000099 an i64; the decimal canonicalisation is the logic contract-psl's number-literal-default.ts holds today. ADR 253, slice B1. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ypes A codec descriptor may now name the literal types its columns accept, as names only. Nothing declares any yet. ADR 253, slice B2 (types). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…type A tag registry entry is now either the lowering entry it has always been, which turns its body into a default itself, or an entry naming the literal type its body is read as. jsonDefaultLiteralTagEntry() is the first of the second kind; no target registers it yet. Consumers that call lower() narrow to the lowering entry. Reading a tag as a literal is wired up with the interpreter, so contract-psl raises an InternalError until then; no registry reaches that branch. ADR 253, slice B3 (types). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The json tag always uses the backtick fence now, escaping backslashes and backticks, which is what resolveBacktickEscapes reverses; a quote fence resolves the full PSL string escapes and would change what a body containing \n reads back as. A refused list literal now carries the index of the element that was refused, so the interpreter can report at that element's span. The refusal shape is one interface, LiteralRefusal, with elementIndex required and undefined off the list path. The two kinds of default literal tag entry are told apart by one exported predicate rather than by each consumer knowing the discriminating key. Literal's scalar arm is ScalarLiteral. jsonDefaultLiteralTagEntry and LiteralTypeName are exported from the codec entrypoint only, beside the literal types, as spec B3 asks. The classification table pins the i16 and i32 minimums from both sides. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Each pack now has one test that walks its registered descriptors and compares codecId to literalTypes against a table, so a codec added without a declaration fails that pack's test. The seven packs are the Postgres target, the SQLite target, relational-core, pgvector, postgis, arktype-json and the Mongo adapter, which names nothing. The two target descriptor adapters forward literalTypes, so the sql/* codecs keep their declarations when a target re-registers them. ADR 253, slice B2 (inventory). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…named A literal type fixes the shape of the value it produces — a whole number under 2^31 is a JSON number, a larger one is digit text, a decimal is decimal text — so a codec that stores a different shape converts inside its existing decodeJson rather than the interpreter branching per codec. The exact integer codecs read a whole JSON number as well as digit text, and the number-valued ones read digit text, refusing anything past the safe integer range with a message naming the limit; sqlite/integer@1 gains that check, which it had for neither shape. pg/numeric@1 reads a JSON number. pg/float4@1 and pg/float8@1 carry NaN and the infinities as the text PostgreSQL reads and writes, in JSON and on the wire, instead of turning them into JSON null; the float codecs that refuse non-finite values still do. pg/vector@1 reads numeral text elements. numberLiteralDefault now takes the written text over the JSON number for a codec whose application value is text, so `Decimal @default(1.50)` keeps its trailing zero in the contract as it does today. That helper is deleted with the interpreter rewrite. ADR 253, slice B2 (coercion). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The numeral-text shape and the three non-finite words were spelled out in four packages, so a change to the accepted syntax in literal-types.ts would have left a codec refusing a literal its descriptor declares. The framework exports isNumeralText and isNonFiniteText, built from the constants classifyNumberText uses, and the codec helpers call them. CodecDescriptorImpl.literalTypes is readonly again; the two target descriptor adapters declare their own readonly member and assign it in their constructors, which is what the interface's `| undefined` now allows. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
PSL now classifies every written default into a literal type, checks that
type against the column's codec by membership, and hands the value to the
codec's decodeJson. No per-type code and no per-codec branch is left in
the interpreter: number-literal-default.ts, which trial-decoded a number
two ways to see what stuck, is gone.
Postgres and SQLite register the json tag, so a JSON default is written
json`{ "plan": "free" }` rather than as a quoted string. A scalar column
accepts a PSL list, which is how a pgvector column takes
@default([0.1, 0.2, 0.3]), and a list element may be a tagged literal, so
Jsonb[] @default([json`{}`]) parses. The codec's declaration decides
whether either is accepted.
Three diagnostics replace the decode crashes: a literal whose type the
codec does not accept, a json body that is not JSON, and a literal the
codec refuses to decode — the last carrying the codec's own message, so a
vector default of the wrong length says so.
A column bound to a value set keeps its member-name default, which is
checked against the value set rather than read as a literal.
The Prisma 7 reader keeps its own copy of the number-through-codec helper
until it is rewritten.
ADR 253, slice B3 and B4.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A list element's incompatibility now names the element, as the read and decode refusals already did: the list branch reads each written element on its own so its type and position are both in hand. Each tag's completion and signature help carries the text of the tag it names — one tagged-literal arm per distinct documentation — instead of every registered tag's text run together. The list arm carries a readable label, so a syntax error reads `... | list of (string | number | boolean | sql`...` | json`...`)` rather than repeating the scalar alternatives and hanging `[]` off the last one; `list()` takes the label. Refusing a lowering tag as a list element has a test. The tag-body switch is exhaustive over the literal types. The fixture codec descriptors live in their own module. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The Prisma 7 reader builds a written literal from its own syntax and hands it to the same reader PSL uses, so both contract sources classify, check and decode a default the same way. The reader's own number handling — a whole-number check per scalar name, a trial decode through the codec two ways, and a JSON.parse for Json columns — is gone. Refusals are structured rather than pre-worded, so each source words its own diagnostic: PSL says the codec is not compatible with the literal, and the Prisma 7 reader says what the default holds and what the column accepts, keeping PSL.PRISMA7_UNKNOWN_DEFAULT. A number too large for its column is now refused with its literal type instead of decoding first. Unchanged: the sqlExpression form for Bytes and DateTime, and the JSON null default, which is still reported before the codec sees the literal. ADR 253, slice B5. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The reader's own JSON.parse is gone, so a malformed Json default now reaches the shared literal reader's unreadable refusal. Both the whole default and one element of a list default are covered, with the parser's message carried through. Also drops a stale doc-comment block left above readLiteralDefault. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
mapDefault writes a literal default through the column codec's declared literal types instead of guessing a PSL form from the JavaScript type, so contract infer prints what contract emit reads. The per-PSL-type formatter table in the Postgres printer is gone, and with it the quoted decimals, quoted NaN and dropped JSON defaults. A decimal now prints unquoted and keeps its trailing zero, NaN and the infinities print as themselves, a json or jsonb default prints as a json tag, and a temporal default prints as the string its codec reads rather than as dbgenerated. The printer restates which codec emit binds to each printed PSL type name, because the authoring namespaces that own that binding sit in the adapter, above the target package. A test in the adapter fails if the two disagree, and a test in the target fails if the type map gains a printed name the table does not cover. A json or jsonb list default's elements are read as JSON documents, as a scalar column's already were, so a Jsonb[] default prints as a list of json tags rather than of quoted text. ADR 253, slice B6. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A literal type says what a value is written as, not that the column's codec accepts every value of that shape: the temporal codecs name string but refuse `infinity`, which PostgreSQL stores and reports verbatim. The printer now passes the value through the column's codec before writing a literal and takes the raw-default fallback when it throws, so a schema infer prints is one emit reads. A new test prints a schema, parses it with the PSL parser and interprets it through the real codec descriptors, asserting every default comes back as the value the database reported — a string with quotes, backslashes, a newline and a non-ASCII character among them, which is also what keeps the printer's escaping and the parser's decoding in step. There is now one PSL string escaper, in the framework, beside writeLiteral. PRINTED_PSL_TYPE_NAMES covers the parameterized type table too. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A CLI journey writes each literal form the slice supports, emits, asserts the contract holds exactly the codecs' JSON forms, runs db init, verifies clean with --schema-only --strict, inserts a row with default values and reads it back through the client with its decoded type: a bigint past 2^53, decimal text keeping its trailing zero, NaN, a JSON object, and both lists. A second test does the same for a pgvector column, whose codec declares a list of element types and checks the length. It found two places that materialised a column's codec without the column's typeParams, so a vector default could neither be re-encoded into the contract nor rendered into DDL: the contract builder and the Postgres DDL renderer now build the codec from its descriptor with the column's own params. The infer round-trip journey asserts a jsonb default prints as a json tag, a numeric keeps its trailing zero and a temporal default prints as the string its codec reads, then emits and verifies clean against the live database. A parity pair emits identical contracts from PSL and TypeScript for nine literal forms. A SQLite e2e case authored 0 and 1 as strings on integer columns, which the contract kept as text while the DDL now writes the number the column stores; it authors the numbers. ADR 253, slice B9. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Only a column carries typeParams, so only its default is encoded through a codec built from the descriptor; the enum and value-set sites go back to the lookup's representative instance, which is what they had and all they need — materialising a parameterized descriptor with no params validates an empty params object and throws. Both production fixes now have a package-level test that fails when the fix is reverted: the contract builder encodes a parameterized column's default through a codec built with the column's own params, and the Postgres adapter renders that column's DDL default the same way, refusing one whose length is not the length the column declares. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The error reference gains the three new diagnostics and the reworded Prisma 7 one. The codec authoring guide gains a section on literalTypes: the ten names, the list form, the rule that decodeJson accepts the value shape of every named type, and what naming nothing means. contract-psl's README says what a literal default may be. ADR 253 closes its open question with the answer the build settled on — a written number's type comes from its own size and precision — and records the list declaration, the coercion rule, the decode check the printer runs before writing a literal, and the corrections the inventory turned up. It is Accepted, as its implemented neighbours are. Upgrade instructions for both audiences: the four schema rewrites an app needs, and what an extension's descriptors, codecs and printer need. ADR 253, slice B8 and B10. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Four passages of ADR 253 still described the design the shaping discussion replaced: the Decision's error example named a literal type that does not exist, the section on where the types are cut contradicted its own table, "Reading a default" said the column decides a scalar's type and pointed at an open question that is now answered, and an alternative said it had been reconsidered there. The reading steps are also in the code's order now: a literal is read, then its type is checked, then the codec decodes it. The upgrade instruction's backslash example did not parse: two backslashes in the schema reach JSON as one, and `\d` is not a JSON escape. Four do, and the page says why. The detection for a number default authored as text accepts either quote character. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s-column-defaults-852235 # Conflicts: # docs/architecture docs/ADR-INDEX.md # packages/2-sql/2-authoring/contract-psl/README.md # packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts
…hrowing The Prisma 7 default reader resolved the column's codec without the type parameters the descriptor carries, so `pg/enum@1` failed to materialize and the failure surfaced as an internal-error diagnostic. Pass the descriptor's typeParams through, and the reader reports PRISMA7_UNKNOWN_DEFAULT. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The value-set check only covered a single written string, so a default like `@default(["aal1", "aal2"])` on a `pg.enum(E)[]` column was read as a literal and refused, which main accepted. Store such a list as written; a list holding anything else still gets the existing diagnostics. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ernal error A default like `Jsonb[] @default(json`{}`)` reached the branch that raised an internal error. Refuse it like any other default a column does not take, with a message saying a list column's default is a list literal. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… cannot hold Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…8 stores The adapter examples in the codec authoring guide omitted the data type the adapter supplies, and both guides still described pg/int8number@1's canonical JSON as a JSON number. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…utes A field declaration may carry attributes between its type and @default, as in `meta Json @db.JsonB @default("{}")`, and the patterns missed those. They now allow any number of intervening attributes on the same line. The extension descriptor detection also matches the two target-owned bases. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s-column-defaults-852235
wmadden
approved these changes
Sep 22, 2026
wmadden-electric
enabled auto-merge
September 22, 2026 06:44
wmadden
reviewed
Sep 22, 2026
…its own An arktype column stores what a jsonb column stores; it differs only in the value it produces in memory and in the schema it checks on the way out. So the descriptor names pg/jsonb and the extension registers no data type. A written json literal still reaches such a column: the tag yields pg/json, pg/jsonb casts from it unchanged, and the codec validates the document. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…t-literal one A cast and an authoring entry are general: the value they are handed need not have come from a column default. They now raise CONTRACT.CAST_REFUSED, and say what was refused and why without mentioning defaults. The JSON body parser keeps CONTRACT.INVALID_JSON_LITERAL, which is about the literal body. PSL diagnostics are unchanged: the interpreter maps any thrown cast to PSL_INVALID_DEFAULT_LITERAL. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A tagged literal's text is built by a small helper from an escaped backtick, so the expected strings and PSL sources read the same to an editor as to the compiler. The assertions are unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
pgvector's list cast and the PSL string escape in relational-core were only reached from other packages' suites, which the per-package coverage report does not see, so both packages fell under their thresholds. Cover them where they live: the vector cast's conversions and refusals, and the escape's four cases. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s-column-defaults-852235 # Conflicts: # packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts
…arity contract re-emitted The four full-text-search tests from main build an interpreter input without dataTypeLookup, which this branch made required. The parity pair expected contract gains the two insert-on-conflict capability flags main added. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
This was referenced Sep 22, 2026
wmadden
pushed a commit
to veksa/prisma
that referenced
this pull request
Sep 24, 2026
… landed, project directory deleted (prisma#30383) ## Linked issue n/a. No Linear project tracked this work. The deferred items filed at close-out are [TML-3282](https://linear.app/prisma-company/issue/TML-3282), [TML-3283](https://linear.app/prisma-company/issue/TML-3283), [TML-3284](https://linear.app/prisma-company/issue/TML-3284) and [TML-3286](https://linear.app/prisma-company/issue/TML-3286). ## Summary Close-out of the remove-dbgenerated project after its three PRs merged: prisma#30325 (the `sql` tagged literal), prisma#30350 (data types and casts, ADR 254) and prisma#30380 (the deletion). The one long-lived artefact moves to `docs/reference/`, the retro lessons land in `drive/`, and the transient project directory is deleted. ## Definition of done, verified on `main` at `ca357d5d3e` - All three slices merged: prisma#30325, prisma#30350, prisma#30380. - `git grep -n dbgenerated -- packages examples test docs skills upgrade-instructions scorecard` returns only the ADR 167 note, the upgrade instructions, the Prisma 7 source and its fixtures, the removed-function message and its tests, journeys asserting the form is absent, and release history. - `git grep -n "NOW_SYNONYMS\|lowerDbgenerated\|dbgeneratedSig\|formatDbGeneratedAttribute\|fallbackFunctionAttribute" -- packages` is empty. - `main` was green through the merge queue for prisma#30380 (typecheck, package, integration and e2e tests, fixtures, lint, deps, docs). - The Supabase reference-fixture verify test is green against the regenerated contract (prisma#30380). - The three ADR amendments are in `docs/architecture docs/ADR-INDEX.md`: ADR 129 (two fences, tag registration), ADR 254 (data types and casts, replacing ADR 184's PSL half), ADR 167 (dated note on the removal). - Final retro recorded; its lessons landed (below). - No unresolved review threads on prisma#30380. ## Where each project decision lives now The project spec's decisions are recorded outside `projects/` before it is deleted: | Decision | Durable home | | --- | --- | | D1 contract shape stays `{ kind: 'function', expression }`; no content-hash envelope | ADR 129, Decision and Alternatives | | D2 two fences, canonical body | ADR 129, Syntax and The canonical body | | D3 who registers a tag, prefix rule | ADR 129, Who owns a tag | | D4 verbatim body, body check, `now()`/`autoincrement()` refusal | ADR 129, What a tag lowers to | | D5 both targets compare through their introspection parser | ADR 129, What a tag lowers to | | D6 no named `gen_random_uuid()` | ADR 129, Alternatives | | D7 TypeScript `sql` tag; `.defaultSql()` deprecated until 8.0.0 | ADR 129 (tag); deprecation note in `contract-dsl.ts`; removal is TML-3286 | | D8 list columns take storage defaults except `autoincrement()` and generators | **added in this PR**: ADR 129, What a tag lowers to; contract-psl README | | D9, D10 written literals have a data type; casts | ADR 254 | | D11 DDL half of ADR 184 out of scope | TML-3283 | | D12 what `contract infer` prints, never a comment | **added in this PR**: ADR 129, Consequences | | D13 Prisma 7 `dbgenerated` maps directly; empty form means no default | contract-prisma7 README | | D14 editor tooling hand-off | `docs/reference/psl-editor-tooling-tagged-literals.md` | | Raw-default verification stays as is | TML-3282 | ## What moves where | File under `projects/remove-dbgenerated/` | Classification | Destination | | --- | --- | --- | | `editor-tooling-brief.md` | long-lived, rewritten at migration | `docs/reference/psl-editor-tooling-tagged-literals.md`, indexed from `docs/README.md`. The project framing ("on the `remove-dbgenerated-delete` branch") became a steady-state description. | | `deferred.md` | transient | Items 2, 3 and 8 are TML-3282, TML-3283, TML-3284. Item 1's decision (raw-default verification stays as is) is recorded inside TML-3282. Items 4 to 7 are done or dated in the specs. | | `spec.md`, `plan.md`, `slices/**` (specs, plans, the slice B brief and handover), `retros.md` | transient | deleted | No file outside the project directory referenced `projects/remove-dbgenerated/`, so nothing was re-pointed. ## Retro lessons landed - `drive/calibration/failure-modes.md` F30: order the regeneration of a committed generated artefact before, or with, the deletion of the form it uses; `fixtures:check` builds every extension's contract space. - `drive/calibration/failure-modes.md` F31: rebuild `dist` before attributing a journey failure to `main`. - `drive/retro/README.md`: an unsettled design decision is named in the brief as a stop and asked, not assumed (slice B's withdrawn first PR). - `drive/pr/README.md`: the merge queue holds an approved, green PR while any review thread is unresolved, including bot threads. - `drive/project/README.md`: before deleting a project spec, map every decision in it to a durable home and list the mapping in the close-out PR. ## Testing performed - `pnpm lint:docs` on the branch: clean. No code changes. ## Skill update n/a. Docs and process files only. ## Checklist - [x] All commits are signed off (`git commit -s`) per the DCO. - [x] I read CONTRIBUTING.md and the change is scoped to one logical concern. - [x] Tests are updated: n/a, doc-only. - [ ] The PR title is in `TML-NNNN: <sentence-case title>` form. No Linear ticket exists for this project. - [x] The **Skill update** section above is filled in. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added a reference guide for editor tooling and tagged defaults in SQL and JSON. * Clarified list-column defaults, type-mismatch handling, and scalar-list support on compatible targets, including unsupported-target behavior. * Expanded guidance on generated artifacts, stale build outputs, unresolved review threads that block merging, and recording project decisions during close-out. * Updated architecture guidance on how defaults are represented and inferred. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At a glance
Every one of those emits, migrates onto a real database, verifies clean, reads back through the client with its decoded type, and
contract inferprints them all back in the same forms. Before this branch,100000000000000099on aBigIntcolumn silently became100000000000000100,1.50on aDecimalcolumn lost its trailing zero, and a JSON default could only be written as a quoted string thatinfercould not print back.The rule behind it is one entity. A data type is a database type made first-class, and it declares what it takes:
A codec is one representation of a data type, and says which:
42on that column is apg/int2, the narrowest Postgres integer type that holds it, andpg/int8casts frompg/int2by turning the number into digit text.100000000000000099is already apg/int8, so no cast runs and no double ever sees it. On anIntcolumn the same value is refused before anything is decoded:pg/int4 has no cast from pg/int8; it casts from pg/int2.Linked issue
n/a. No Linear ticket exists for this project; this is the second of three PRs removing
dbgenerated. Builds on #30325 (thesqltagged literal). Design: ADR 254 — Data types and casts. This branch carries #30334's ADR commits and amends the ADR to the implemented design, so #30334 can close when this merges. The PR that deletesdbgeneratedfollows.Skill update
n/a. No agent skill under
packages/0-shared/skills/describes@defaultvalues. The author-facing surface is documented in docs/reference/codec-authoring-guide.md, the schema surface in packages/2-sql/2-authoring/contract-psl/README.md, and the migration in upgrade-instructions/pending/data-types-column-defaults/.Decision
Three things land together, and none works without the others.
Data types. A data type is a database type made first-class (
pg/int8,pg/jsonb,sqlite/bigint,pgvector/vector), registered by the pack that owns it. It names the one canonical form the contract stores for its values and declares its casts: for each other type whose values it takes, a pure function from that type's canonical form to its own. Casts are declared by the receiving type, never the source, so there is at most one cast per pair and only the owner of a type decides what it takes.Every codec names one.
CodecDescriptor.dataTypeis required, so a codec that names no type does not compile and one whose type nobody registers is an assembly error. Several codecs may represent one type:pg/int8@1andpg/int8number@1both representpg/int8and differ only in the value they produce in memory, and they now share that type's contract form.PSL support belongs to the type. The pack that owns a type contributes an authoring entry for it: the syntax it is written in, how the text is read into the canonical form, and how a stored value is written back. The interpreter, the reader for the earlier Prisma schema language,
contract inferand the language server all read those same entries, so a new type needs no change in any of them.How it fits together
The framework learns what a data type is.
data-type.tsis the whole vocabulary: a brandedowner/nameid validated on the way in,Cast,listCastfor a type whose single value holds several elements, and a lookup. It is family-blind; it names no database and no target.Descriptors name their type, and templates defer it.
CodecDescriptorgains one required member. A codec whose type depends on the target that adopts it (the five shared relational codecs, wheresql/int@1ispg/int4on one target andsqlite/integeron another) extendsCodecDescriptorTemplateImplinstead, and the target names the type when it adapts the template (codec-descriptor.ts).Assembly checks the stack.
control-stack.tscollects every pack's types and PSL support and refuses four things across packs: a codec whose type nobody registers, an entry or cast naming an unregistered type, two entries claiming one written form, and a cast from a type no contract source can write.Every pack declares. Postgres and SQLite declare their types and casts (
data-types.ts); the SQL family registers none and instead owns the arithmetic every target repeats: the numeral canonicaliser, the exponent-free writer, the integer-width classifier factory and the JSON reader (data-type-support.ts).The readers and the printer switch over. Reading a default is now: the entry for the written syntax gives a typed value; the column's type takes it directly or through its cast; the column's codec validates the canonical form; the canonical form is stored (
data-type-default.ts). Printing is the inverse, with a read-back check before anything is written (default-mapping.ts).Reviewer notes
refactor: the literal-types surface is gone). It removes the framework's literal-types modules,literalTypeson every descriptor, andControlMutationDefaults.defaultLiteralTagRegistrywith its entry union. Worth spot-checking that thesqllowering entry now has exactly one home, in the authoring entries, and that the language server reads tag documentation from there.contract emitwas broken in a way no package test could see. The PSL provider was not passing the data type lookup through to the interpreter, so every cast missed and every numeric default was refused, while every package test passed, because each built its own interpreter input.fixtures:checkcaught it. The lookup is required on the interpreter input now, and a package test drives a numeric default through the provider seam the CLI uses; reverting the threading makes that test fail.countaggregate's declared empty-result JSON changed from0to'0'in both targets, andpg/int8number@1's JSON projection became the decimal-text cast its sibling codec already used. The value a caller receives is still the number0; the pre-existing aggregate tests pin it. That follows frompg/int8number@1andsqlite/bigintnumber@1carrying digit text, which they must, because they are codecs of a type whose canonical form is digit text. Three test fixtures follow it.sqlite/integerandsqlite/bigintare distinct although both store as INTEGER, andsqlite/text,sqlite/datetimeandsqlite/jsonare distinct although all store as TEXT. The rule is that a target declares the types it distinguishes; the ADR now says so.trueon SQLite is refused withthis target has no data type for a boolean value. That is the decided behaviour, not an oversight.contract.jsonthat mentions those codecs was checked. A user with one is covered by the upgrade instructions.nativeTypeleaving the contract; type constructors naming a type and a codec; function arguments typed by a data type. The ADR describes all of it; the code implements the parts this slice needs. Where the ADR described the future state as present, the ADR commit corrects it and its status line says what shipped.Behavior changes & evidence
data-type-support.ts,data-type-entries.ts. Evidence:data-type-authoring.test.tspins every width boundary,-0, leading zeros and kept trailing zeros.@default(json`{}`)and printed back the same way; a quoted string on aJsonbcolumn is refused, becausepg/jsonbcasts frompg/jsonand not frompg/text.data-type-default.ts. Evidence:interpreter.defaults.data-types.test.ts,data-type-defaults.e2e.test.ts.data-type-default.ts,defaults.ts. Evidence: the eleven refusal cases ininterpreter.defaults.data-types.test.tsand the Prisma 7 fixtures indefaults.test.ts.contract inferprints a literal where it used to printdbgenerated, and never prints one it cannot read back: it parses and casts the printed text and requires the stored value again.default-mapping.ts,infer-default-codec.ts. Evidence:print-psl.data-type-defaults.test.ts, including the'infinity'::timestampfallback.codecs.ts,sql-codec-helpers.ts. Evidence: the fourcodec-strictness.test.tssuites, which pin every shape eachdecodeJsonused to coerce.control-stack.ts. Evidence:data-type-assembly.test.ts,data-type-descriptor.types.test-d.ts.Compatibility
Breaking for schemas that wrote a JSON, decimal or non-finite float default as a quoted string, and for a
Jsonbcolumn given a written list. Breaking for extension authors: every codec descriptor must name a data type,decodeJsonmust stop accepting anything but the canonical form, and the tag registry is gone. Contracts holding anpg/int8number@1orsqlite/bigintnumber@1column with a literal default change form and needcontract emitthendb sign; no contract in this repo has one. All of it is written up for both audiences in upgrade-instructions/pending/data-types-column-defaults/.Testing performed
pnpm build: cleanpnpm typecheck: cleanpnpm test:packages: greenpnpm test:integration: greenpnpm test:e2e: greenpnpm lint,pnpm lint:deps,pnpm lint:throws,pnpm lint:docs: cleanpnpm lint:framework-vocabulary: 276 sites, threshold unchangedpnpm fixtures:check: no contract changepnpm check:upgrade-coverage --mode pr: cleanFollow-ups
.default()cannot take abigintor a non-finite number, so PSL is the only surface for aBigIntdefault past 2^53 and forFloat @default(NaN).useDevDatabaseintest/integrationpasses its timeout asbeforeAll's third argument, which vitest ignores, so journeys flake at 5 s on a loaded machine.Alternatives considered
encodePsl/decodePsl, the sketch in ADR 184). Every codec becomes coupled to PSL's tokenizer and escaping, and there is no check before a decode fails.decodeJson. Two codecs of one type repeat the same fact and the same conversion, anddecodeJsonends up accepting shapes the codec never writes.sql/i8,sql/jsonand so on) that every target's types cast from. It invents types no database has, and most of its casts would return the value unchanged.Infinitywhen a written number is too large for a double. The database refuses that conversion, and storing the word would make a written number indistinguishable from a writtenInfinity.Checklist
git commit -s) per the DCO.TML-NNNN: <sentence-case title>form. No Linear ticket exists for this project, so the title carries no prefix.Notes for the reviewer
See "Reviewer notes" above.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
contract infernow emits more defaults as readable PSL literals instead of raw database expressions.Bug Fixes