Repository navigation
TML-3531: Each default has one stored form, owned by its data type; dates, times and bytes are written with tags - #30750
Merged
Merged
Conversation
Amends ADR 254 and supersedes ADR 184. Inserts the value-ownership slice before the verify slice in the data types project, with its plan. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Leads with a value followed from PSL to the database, states the four decisions, and builds up values, codecs, casts and PSL syntax in turn. Drops the build-status block and every reference to earlier states. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… column's parameters Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… column's parameters Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…em with four methods
DataTypeValue { type, params, value } is constructed only by a data type, through
fromContract and withParams; toContract gives the stored JSON. Every data type
declares a reader of its stored JSON, and parameter limits (int4 and int2 ranges,
char and varchar lengths, numeric(p,s), bit lengths, vector(n)) move from codecs
to the types. numeric(p,s) spells a value with the column's scale.
Codec, CodecImpl, the SQL Codec, MongoCodec and mongoCodec() have
fromDataTypeValue, toDataTypeValue, fromWire and toWire. A codec is built with
its data type and the column's parameters, and toDataTypeValue constructs its
result through that type. Every codec and every caller of encodeJson and
decodeJson is converted.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…codec is built only when called A contract names a family codec with sqlIntColumn() and the like; the target's adapted descriptor builds the codec. The template's factory now throws when its codec is built, not when the helper is called. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…lt spelled with its scale A Numeric(10, 2) @default(1.5) column stores "1.50", which PostgreSQL also prints for the column default and for a row; 1.234 and 123456789.5 are refused with PSL_INVALID_DEFAULT_LITERAL (TML-3479). The date and time types refuse the forms only Temporal.from read. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ata type values Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…four codec methods Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… four codec methods Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… four codec methods Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s use the four codec methods The Prisma 7 reader's Decimal defaults are numeric(65,30) values, so their expected contracts now hold the value with thirty fraction digits, as PostgreSQL prints it; the golden planner manifest records the new fixture hashes. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… long decimal is padded to its scale Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… give; a codec refuses a value of another type fromContract reads JSON under the parameters and refuses it unless it is already in the spelling the parameters give, naming that spelling. A codec builds its value through a constructor inside the data type module that reads and spells under the parameters, so dataTypeValueFor no longer goes through fromContract. readReportedValue reads a value the database reports or returns, in any spelling the type reads; the ORM include and aggregate reads, contract infer and the codec test kits use it. CodecImpl and mongoCodec() refuse a value whose type is not the codec's data type. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… value as numeric scale does A date or time type and interval with a precision refuse a value with more fraction digits of a second than the precision, rather than round it as PostgreSQL would: time(0) refuses 00:00:00.5. A character value is spelled without the spaces that pad it to its length. A geometry column with an SRID reads only geometries in that SRID. Fixtures that held a scaled numeric or a padded character in another spelling now hold the one spelling. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… a value that does not come back, and the JSON channel follows toDataTypeValue Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…odec A module-level map from a type to its constructor missed when a contract source and the CLI load two copies of framework-components, which fixtures:check does. The type carries the constructor itself, as fromCodec, and dataTypeValueFor calls it. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… malformed geometry hex and a vector's length are refused by the type A date, time or interval value with no precision holds microseconds, so a seventh fraction digit is refused rather than rounded. Hex that is not EWKB on a geometry column with an SRID is refused through refuseJsonValue, naming the type. mongo/vector reads exactly its length's numbers when the column sets one. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nd compares it with the row The Postgres kit reads each case's column as an ordinary row through the runtime driver and through the codec's JSON projection, and requires fromWire to read both to the application value the case wrote. Projections that put another value into the JSON now project the text PostgreSQL prints: bytea (hex, not base64), interval (PostgreSQL's interval text, not an ISO duration built in SQL), json, jsonb and arktype-json (a string document otherwise reaches fromWire unquoted), text-array, pgvector (the row's shortest decimals, not widened doubles) and PostGIS geometry (HEXEWKB). pg/text-array@1's fromWire reads the array text the driver returns. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… compares it with the row The SQLite kit reads each case's column as an ordinary row and through the codec's JSON projection, and requires fromWire to read both to the application value the case wrote. Where JSON cannot carry the row's wire value, fromWire also reads what the projection writes: sqlite/integer@1 and sql/int@1 read the decimal text an integer is cast to, sqlite/real@1 and sql/float@1 read the text Infinity and -Infinity, and sqlite/blob@1 reads the hex text hex() writes. A row the driver cannot read, an INTEGER past 2^53, is reported as such once the projection is shown to carry the value. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…es with fromWire An include or an aggregate comes back from the database as JSON. The ORM now reads each column in it with the codec's fromWire and the call context an ordinary row's cell gets, as the runtime reads a row, instead of reading it as a stored value. Reading an include is asynchronous. An aggregate descriptor's empty answer is a wire value of its result codec, emptyResultWire, read with fromWire. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s a data type id The test passed but did not typecheck: columnCodec.dataType takes a DataTypeId. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Text such as 2024-01-01 12:00:00, which Prisma never writes but another tool may, is now read as UTC, as SQLite reads it, instead of in the machine's time zone. The app instruction says so and shows how to find such rows. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… in seconds Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…keeps running on it The app text said this release refuses to load a SQLite or PostgreSQL contract an earlier release emitted. Only the CLI checks the contract against the stack; an application built with this release keeps running on the old contract. The text now says so, and to upgrade before the next db migrate. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ier release to the upgrade instructions The fix said to re-run contract emit. For a contract an earlier release emitted that neither upgrades its migration snapshots nor succeeds while the schema still has a default the earlier release accepted. The fix and the next actions now name both cases: the app upgrade instructions, at the link MIGRATION.OPERATION_OPTION_REMOVED already uses, for a contract an earlier release emitted, and contract emit for one this release emitted. The error reference and the stale-default journeys follow. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…he database hold Human db verify output printed only the path of a mismatched default; the values were in the JSON output only. The default node now explains a mismatch with both values, as it already explained a default the codec could not read: The contract holds "3.10", and the database holds "3.11", with the text the database reports when it differs. The explanation is the one place a mismatch adds text to its label; no other node kind has one. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/2-mongo-family/2-authoring/contract-psl/test/derive-json-schema-helpers.ts # packages/2-mongo-family/2-authoring/contract-psl/test/provider.interpret.test.ts # packages/2-mongo-family/2-authoring/contract-psl/test/provider.test.ts # packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts # packages/2-sql/2-authoring/contract-prisma7/test/fixtures/defaults/expected-contract.json # packages/2-sql/2-authoring/contract-prisma7/test/fixtures/list-defaults/expected-contract.json # packages/2-sql/2-authoring/contract-prisma7/test/fixtures/number-default-spellings/expected-contract.json # packages/2-sql/2-authoring/contract-prisma7/test/fixtures/number-defaults/expected-contract.json # packages/2-sql/2-authoring/contract-psl/test/interpreter.no-check.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/inferred-psl/inferred-psl.list-element-nullability.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/inferred-psl/inferred-psl.literal-defaults.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/inferred-psl/inferred-psl.nullable-list.test.ts # test/integration/test/cli-journeys/bytea-defaults.e2e.test.ts # test/integration/test/cli-journeys/infer-roundtrip-fidelity.brace-array-defaults.e2e.test.ts # test/integration/test/cli-journeys/infer-roundtrip-fidelity.prisma7-defaults.e2e.test.ts
Contributor
|
Important Review skippedToo many files! This PR contains 721 files, which is 421 over the limit of 300. To get a review, reduce the PR to 300 files or fewer by splitting it into smaller PRs or changing its base branch. Usage-priced reviews support at most 300 files. ⚙️ Run configuration
⛔ Files ignored due to path filters: 35
📒 Files selected for processing: 721
You can disable this status message by setting the
Comment |
@prisma/orm-extension-arktype-json
@prisma/orm-extension-middleware-cache
@prisma/orm-extension-paradedb
@prisma/orm-extension-pgvector
@prisma/orm-extension-postgis
@prisma/orm-extension-supabase
@prisma/orm-family-mongo
@prisma/orm-family-sql
@prisma/orm-framework
@prisma/orm-mongo
@prisma/orm-postgres
@prisma/orm-sqlite
@prisma/orm-target-mongo
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
Contributor
size-limit report 📦
|
…, as every CLI path does SQLite introspection reads a literal default with the column's codec only when it is given the contract; without it the default keeps its raw text and compares unequal to the contract's value. The harness verified without it. Every product path that verifies passes the contract: db verify, db init and db update, migrate, and the migration runner's own post-apply check. db schema and contract infer introspect without one but do not verify. So the harness now passes the destination contract, as db update does. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…atform reads it node:sqlite throws for an INTEGER past 2^53 when it is not asked for a bigint, but on CI's Linux it returns -2^63, the one value whose magnitude int64 cannot hold, as a number, which fromWire refuses (row-from-wire-rejects); on macOS it throws (row-execution). Both are right for their platform, so the case asks node:sqlite which it does and records that kind. The deferred note says the same. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… the framework printer does The codemod keeps a copy of the tag printer for the rc.17 upgrade. The framework printer now doubles a backslash only before another backslash or at the end of a backtick body, where it would be read as an escape; the copy doubled every backslash. Both spellings read back as the same text, so the change only makes the codemod print what contract print prints. The parity test gains a doubling case, and the copies the upgrade instructions carry, which a test holds byte for byte to this script, follow. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… commit on main The index-name list on line 113 of the 2026-10-07 migration statements QA report matches generic-api-key. It was ignored under the commit that added it on its branch; on main the file came in through squash commit 994aa73, so the same finding is ignored under that commit too. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…a-type-values Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts # packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts # test/integration/test/planner-golden/manifest.json
…re this branch keeps it #30752 classes this.setDefault as widening when the start contract gives the column a default, and read the start schema column's raw default text. On this branch the schema built from a contract carries the default as resolvedDefault, and its raw text only on the introspected side, so every setDefault was additive. It now reads resolvedDefault. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…a-type-values Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/1-framework/1-core/framework-components/test/codec-types.types.test-d.ts # packages/1-framework/1-core/framework-components/test/data-type.test.ts # packages/1-framework/3-tooling/cli/test/config-types.test.ts # packages/2-mongo-family/1-foundation/mongo-codec/test/codecs-ctx.test.ts # packages/2-sql/4-lanes/relational-core/test/ast/codec-factory-ctx.test.ts # packages/2-sql/4-lanes/relational-core/test/ast/codec-factory-ctx.types.test-d.ts # packages/2-sql/4-lanes/relational-core/test/ast/codec-factory.test.ts # packages/2-sql/4-lanes/relational-core/test/ast/codec-factory.types.test-d.ts # packages/2-sql/4-lanes/relational-core/test/ast/sql-codec-helpers.test.ts # packages/3-extensions/arktype-json/test/arktype-json-codec.test.ts # packages/3-extensions/pgvector/test/codecs.test.ts # packages/3-extensions/pgvector/test/data-types.test.ts # packages/3-extensions/postgis/test/codecs.test.ts # packages/3-mongo-target/1-mongo-target/test/codecs.test.ts # packages/3-targets/3-targets/postgres/test/codecs.test.ts # packages/3-targets/3-targets/postgres/test/integer-representation-codecs.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract.enum-adoption.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/infer-sql-expression-literals.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/inferred-psl/inferred-psl.data-type-defaults.test.ts # packages/3-targets/3-targets/postgres/test/psl-policy-authoring.test.ts # packages/3-targets/3-targets/sqlite/test/codec-strictness.test.ts # packages/3-targets/3-targets/sqlite/test/codecs.test.ts # packages/3-targets/3-targets/sqlite/test/data-type-authoring-tags.test.ts # packages/3-targets/3-targets/sqlite/test/data-type-declarations.test.ts # packages/3-targets/3-targets/sqlite/test/integer-representation-codecs.test.ts # packages/3-targets/3-targets/sqlite/test/structured-errors.test.ts # packages/3-targets/6-adapters/postgres/test/migrations/data-transform.test.ts # packages/3-targets/6-adapters/sqlite/test/codecs.test.ts
wmadden
approved these changes
Oct 19, 2026
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Oct 20, 2026
…the close-out missed (prisma#30797) This deletes `projects/date-time-default-text/` (`spec.md` and `plan.md`). The plan for TML-3302 said to delete this directory at close-out. The deletion was made on the branch of [prisma#30532](prisma#30532), but the squash merge did not carry it, so the files stayed on `main`. They describe the "canonical form" design for date and time defaults. TML-3531 ([prisma#30750](prisma#30750)) has since replaced that design, so the files are now wrong as well as finished. ADR 254 is the current record. Nothing in the repository links to the directory. Agent: anubis-80 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
This was referenced Nov 20, 2026
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.
A Postgres model with a date default, before and after this pull request:
Where the
dueandtotaldefaults end up:contract.json"2024-01-31","1.5""2024-01-31","1.50"DEFAULTclausedb verify@default("2024-01-31")Expected date`...`; write date`2024-01-31`The decision
A column's data type owns its values, and a codec only converts them. Every default is stored in one form, decided by the data type, and every tool reads and writes it through the same two pieces. This rewrites and implements ADR 254, "Data types and casts", for Postgres, SQLite, Mongo and the pgvector, PostGIS and arktype-json extensions.
Two words this description uses
pg/date,pg/numeric,sqlite/integer,pgvector/vector. It knows the type's name in DDL and its parameters, such asnumeric(10,2).pg/timestamptzcolumn can be read as aDate, aTemporal.Instantor text, depending on the codec the schema picks.The problem
Before this change the codec decided how a default was stored, and several places had their own code to make different spellings of one value equal.
DatetoTemporalcould changecontract.json.2024-01-01T00:00:00Zin the contract and theDEFAULTclause, but every row the application wrote held2024-01-01T00:00:00.000Z.db verifyand the planner each needed code to treat those as equal.contract infercould not tell a date from text when printing it back.How it works
The data type owns the value. A value is
{ type, params, value }, wherevalueis the JSONcontract.jsonstores. Only the data type builds one. Each data type declares how to read a value (it accepts every spelling it understands and refuses anything else) and how to spell it (the one form it stores): lower case for a uuid, two fraction digits onnumeric(10,2)so1.5is stored as"1.50", ISO 8601 text for dates and times. Loading a contract refuses a stored value in any other spelling. Because every codec's value goes through the data type, two codecs of one type can no longer store a value differently.The codec converts. A codec now has exactly four value methods. Two convert between the data type's value and the application's value (
fromDataTypeValue,toDataTypeValue). Two convert between the application's value and what the database driver sends and receives (fromWire,toWire). The oldencode,decode,encodeJsonanddecodeJsonare gone, and every codec in the repository is converted.Every tool goes through those two.
DEFAULTclause: the planner hands the value to the column's codec and writes what the codec writes for a row. The SQLite datetime default and a row now hold the same text.db verifyand the planner compare values, not text. The per-type normalising code (toCanonicalFormand the planners' copies of it) is deleted.includeor an aggregate, are read with the samefromWireas an ordinary row.Values with their own grammar are written with a tag. A date, a time, an interval or bytes is written with its type's tag,
date`2024-01-31`, and a quoted string on such a column is refused with the tag to write. Postgres gainsdate,time,timetz,timestamp,timestamptz,intervalandbytea; SQLite gainsdatetimeandblob. The language server offers only the tags a column takes. PostgreSQL's way of writing years before 1 AD and after 9999 is handled in one place.SQLite's datetime and JSON columns get their own data types.
sqlite/datetimeandsqlite/jsonare stored as SQLitetext, so their DDL anddb verifydo not change, but their values are now typed.contract infer,contract printand the Prisma 7 reader use the same values. Infer reads a database default with the codec of the type it prints and writes it back with the type's tag. The Prisma 7 schema reader stores date, time and bytes defaults as values instead of SQL expressions, and refuses aDateTimedefault with more precision than its column rather than rounding it, naming what PostgreSQL would store.What users have to do
Upgrade instructions ship in
upgrade-instructions/pending/data-type-values/, for applications and for extension authors.contract emit, thendb sign."1.5"onnumeric(10,2)) is refused by the CLI until it is re-emitted and signed.What changes in committed files
contract.d.tsfiles are regenerated forsqlite/datetimeandsqlite/json. SQLite DDL does not change.Decimaldefaults are written with the column's full scale. PostgreSQL stores the same values, which was checked against a database. No other DDL changes.How it was checked
include.projects/data-types-completion/slices/3/manual-qa.md: a SQLite project built with the previous release, upgraded by following the instructions; Postgres defaults on every date and time type, including years before 1 AD and after 9999, through migrate, verify, infer and print; and the Prisma 7 side-by-side flow with date defaults.projects/data-types-completion/slices/3/build-review.md.Not in this pull request
db verifycomparing a column's type through its data type, and the Prisma 7 reader printing the constructor each data type marks: TML-3387.projects/data-types-completion/deferred.md, such as a SQLite datetime stored as seconds or a Julian day number, which still reads as milliseconds.Tickets
Linear TML-3531, the third part of the "Data types own column types" project. It also closes TML-3394 (the Prisma 7 reader stored a date default as SQL), TML-3396 (PostgreSQL's year text), TML-3404 (SQLite wrote a datetime default in one fixed form) and TML-3405 (TypeScript defaults bypassed the data type), and it replaces TML-3406, whose code it deletes. The design was first proposed in #30656, closed so it is reviewed here next to the code.
Alternatives considered
DatetoTemporalwould change the contract.JSONmakes SQLite convert a document like"42"to a number, and every existing table would need rebuilding.Agent: frigg-97
🤖 Generated with Claude Code