Repository navigation
TML-3713: contract infer, contract print, the Prisma 7 reader and orm init write the convenience date and time types - #30858
Conversation
…'s client did Prisma 7 filled @default(now()) on the client and also wrote the database default. The reader kept only the database default, so a create through Prisma 8 got the database's clock in the session time zone. The reader now also resolves the now generator for the column's codec through the generator function registry, and refuses @default(now()) on a column no now generator fills. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…rough Prisma 8 A raw INSERT on the same session still gets the database default, in Tokyo wall-clock time. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…enerator on create The storage hash is unchanged; the execution hash changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…efault and a now generator on create Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…@default(now()) now writes on create Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… create for @default(now()) Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…der's contracts, without a ticket reference Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nd nothing for extension authors The marker holds only the storage and profile hashes, and the storage hash does not change, so db sign does nothing here. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…eld's own terms The refusal names the field type the user wrote, or the native type that makes the column not a date or time, says Prisma 7 refuses the schema too, and says what to change, like the reader's other refusals. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The Tokyo case now asserts +9 hours on the connection the application's creates run on, instead of checking a separate connection. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…a list field now(), uuid() and the other functions fill one value, so on a list column they gave a scalar generator or a column default PostgreSQL rejects. The refusal says to write a list literal instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…and test the list-field rule on its own The one-member set and the helper that took a function name are replaced by a check for now() and a now-specific refusal. The rule that refuses a function default other than dbgenerated on a list field gets its own tests, for autoincrement(), uuid() and now(). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ecomes it findAuthoringTypeChoiceCall finds the first type choice whose row names the constructor, builds its arguments by name from the row and the call, leaves out every argument whose omission still gives the same codec and parameters, and finds nothing when no call to the choice reproduces them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…sion 6 PostgreSQL stores microseconds whether a timestamptz, timestamp, time, timetz or interval column declares precision 6 or none, so the normal form of these data types counts an omitted precision as 6, and db verify and the planner see no difference between the two. The catalog text a migration postcheck compares with format_type is now the text for the type as written: PostgreSQL prints a bare timestamptz as timestamp with time zone, not with a precision. The normal form is used only where no catalog text takes the written parameters, as numeric(10) prints numeric(10,0). Contracts keep their parameters as written, so no stored contract or hash changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… types Each date and time data type now marks the explicit type its convenience default gives: TimestamptzJsDate, TimestampJsDate and IntervalString instead of the string and parts types. contract infer picks that type and writes the convenience call that becomes it, by name and with only the arguments that differ from the defaults, so a timestamptz(3) column is DateTime and a timestamptz with no declared precision is DateTime(precision: 6). contract print writes the convenience call wherever one becomes the column's explicit type exactly, and the explicit type otherwise, as for a timestamp read as Temporal.PlainDateTime. A Date holds milliseconds, so a timestamp default with more digits, or infinity, keeps its raw SQL expression rather than a default a millisecond off. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…enience date and time types prisma7Schema reads a Prisma 7 DateTime as TimestampJsDate(3), printed DateTime(column: timestamp), and @db.Timestamptz(p) as TimestamptzJsDate(p), so an adopted application reads a JavaScript Date as Prisma 7 gave it, and @updatedat and @default(now()) write a Date. temporal.CreatedAt and temporal.UpdatedAt are built on the type bare DateTime becomes, and their String and JsDate variants are removed. orm init writes createdAt DateTime @default(now()) @onCreate(now()) and updatedAt temporal.UpdatedAt, in PSL and in TypeScript. db verify compares a timestamp default with the value the column holds, not with a Date codec's millisecond reading of it, so a Prisma 7 database with a microsecond default still verifies clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…rade instructions The example re-emits its contract, records the signed snapshot of the new storage hash, and prints updatedAt from the Date it now reads. The upgrade instructions give the re-emit, db sign and code change for prisma7Schema projects, and the rewrite of each removed created-at and updated-at alias. The earlier instruction for the Prisma 7 now() default names the type the reader now picks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… leave it Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The scalar types reference, the gotcha about Prisma 7 dates, the Prisma 7 reader, PSL, TypeScript and Postgres target READMEs, ADR 275's alias note and the prisma-8 skill now say what contract infer, contract print, prisma7Schema and orm init write, that an omitted precision compares equal to 6, that a Date drops microseconds, and that the created-at and updated-at aliases are on DateTime. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…bulary ratchet The Postgres TypeScript starter that orm init writes now types its timestamps with field.column(type.DateTime()) and field.column(type.temporal.UpdatedAt()). The starter is Postgres code held as a template string in the CLI, and its body is one template chunk with no earlier counted occurrence to share, so the threshold rises from 237 to 238. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
renderSqlCatalogText rendered the text for the parameters as written whenever a catalog text took them, which is how PostgreSQL prints a type but not how every database does: MySQL prints datetime(0) as datetime. A SQL data type may now declare catalogParams, the parameters its catalog prints for those written, and the normal form is used where it declares none. The Postgres date and time types declare that the precision is printed as written. The contract side of the schema tree uses the same parameters, so a bare timestamptz column shows as timestamptz in verify messages rather than timestamptz(6), and the infer test fixtures report catalog text as PostgreSQL prints it for the type as written. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
findAuthoringTypeChoiceCall now also returns the type constructor call the type choice call resolves to, and contract infer records that call for the column's default checks. A bare time column is written Time and recorded as TimeString with no precision, as emit reads it, instead of with the precision 6 of the column's normal form. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A codec refuses in fromDataTypeValue a value its application value cannot hold exactly. The Postgres timestamptz and timestamp Date codecs and MySQL's datetime Date codec now do so for digits below a millisecond, naming the text and Temporal types that hold them, so a PSL default such as timestamptz`2024-01-01T01:00:00.123456Z` on a DateTime field is refused at authoring. Reading a row is unchanged: fromWire still gives the Date at the millisecond. A TypeScript contract cannot write such a default, because .default() on a Date field takes a Date. contract infer prints a reported timestamp default as a literal only when the codec reads it exactly, beside the existing JSON check, and otherwise prints the raw expression. db verify reads both sides through the codec again, so an inferred microsecond default verifies clean and plans nothing; the adapter's held-value comparison and its helper are removed. The default reader reports the codec's refusal as its own kind carrying the stored value, or for a list every element. The Prisma 7 target binding gains refusedLiteralDefault, which writes that default's SQL; the Postgres binding writes a quoted literal cast to the column type, or ARRAY[...]::type[] for a list. A Prisma 7 DateTime default with microseconds still loads, and a database Prisma 8 migrates from it holds every digit and verifies clean. The upgrade instruction says what to write for a PSL default on a Date field with digits below a millisecond. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… refused list element The Postgres Prisma 7 binding writes a date or time default with the year text PostgreSQL reads, through postgresYearText, so a year before 1 or after 9999 is written 0044-03-15T00:00:00.123456 BC or 10000-01-01T00:00:00.123456Z, not with a signed year PostgreSQL rejects. contract infer prints the raw expression when the column's type does not read a body its codec read, instead of throwing. A PSL list default with an element the codec refuses and a later element refused for another reason is reported at the first. ADR 254 says a Date column's defaults are compared as the application reads them, so a difference below a millisecond is not reported. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
⛔ Files ignored due to path filters: 10
📒 Files selected for processing: 57
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
@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: |
size-limit report 📦
|
… into the tools Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
contract infer, contract print and the Prisma 7 reader already take the option names from the type choice table, so they now write DateTime(storage: timestamp), Time(storage: timetz) and DateTime(as: temporal, precision: 3). This updates the tests, inline snapshots, READMEs, docs, skills and upgrade instructions that spelled the old names. The negative type test that writes { value: 'string' } keeps it on purpose.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The PostgreSQL now entry passes the column precision to timestampNow for pg/timestamptz-date@1 and pg/timestamp-date@1, as it already does for the string and time generators, and the SQL family's timestampNow rounds the Date down below that precision. A Prisma 7 @db.Timestamp(0) @updatedat field generated .700 in the client and PostgreSQL stored the next second; now both hold the second. SQLite and MongoDB pass no precision and are unchanged. The precision is recorded beside the generator, so contracts with such a column change their execution hash; the storage hash does not change. The fixtures, the prisma7-adoption example and the Prisma 7 reader's expected contracts are re-emitted, and the upgrade instruction says to re-emit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
RUNTIME.TEMPORAL_UNAVAILABLE now says, for both a codec and a generator, that a convenience type at its default needs no Temporal: DateTime reads a JavaScript Date, and Date, Time and Duration read ISO 8601 strings. The generator's fix no longer names the string presets, and its why says a Temporal value rather than a Temporal.Instant, since plainDateTimeNow, plainDateNow and plainTimeNow raise it too. The error reference lists pg/timestamp-instant@1 among the Temporal codecs, names now() attributes as a cause, and gives the same way out. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
@db.Date and @db.Time read the same ISO 8601 text as before, but @db.Timetz now reads a full offset, 10:00:00+02:00 or 10:00:00Z, where it read 10:00:00+02 and 10:00:00+00. The table says so and points to the ISO strings change for the rest instead of repeating it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
510d1a0
into
tml-3712-convenience-date-time-types
…, read ISO strings on every server, and get the design for convenience types (prisma#30834) ## Linked issue Refs TML-3709 (Linear project: Convenience date and time types). Fixes TML-3418, TML-3711 and TML-3719, which were reviewed as prisma#30851, prisma#30844 and prisma#30839 and squash-merged into this branch so they reach `main` together. ## Summary ```prisma model Event { id Int @id at TimestamptzTemporal(3) // was Timestamptz(3): timestamptz(3), read as a Temporal.Instant legacyAt TimestampJsDate(3) // new: timestamp(3), read as a JavaScript Date, stored as UTC day DateTemporal // new name: date, read as a Temporal.PlainDate period IntervalString // new: interval, read as "P1Y2M" label TimestamptzString // reads "2024-01-01T00:00:00Z" on every server } ``` **The decision: PostgreSQL's explicit date and time types become a complete, predictable layer, and ADR 279 records how convenience types `DateTime`, `Date`, `Time` and `Duration` will be built on top of it.** This PR lands the design and the three changes the convenience types need first. The convenience types themselves and the tools that write them follow in prisma#30847 and prisma#30858. ### Why Prisma 7 had one date type, `DateTime`, always read as a JavaScript `Date`. That is easy to learn, but a `Date` is a moment in time, so it is the wrong value for a calendar date: a birthday created at local midnight east of UTC is stored as the day before. Prisma 8 replaced it with explicit types, each naming the column type and the value the application reads: `TimestamptzJsDate` is a `timestamptz` read as a `Date`. Every choice is visible, but a column type with three kinds of value has three names, and nothing says which to start with. The research behind this project also found three defects in the explicit layer: the string types returned text that depends on the server's settings, `timestamp` and `interval` lacked codecs a sensible default needs, and an adopted Prisma 7 schema stored local time where Prisma 7 stored UTC. ### 1. The design: ADR 279 ADR 279, "Convenience types choose an explicit type from their arguments", adds a second kind of type declaration. A convenience type is named for what a field means, and its optional arguments `as:` (the value the application reads) and `storage:` (the database type) pick exactly one explicit type from a table: ```prisma paidAt DateTime // exactly TimestamptzJsDate(3) settledAt DateTime(as: temporal) // exactly TimestamptzTemporal legacyAt DateTime(storage: timestamp) // exactly TimestampJsDate(3) shipBy Date // exactly DateString ``` The contract records only the explicit type, so nothing below PSL and the TypeScript builder changes. Defaults need no setup: `DateTime` reads a `Date`, and `Date`, `Time` and `Duration` read ISO 8601 strings, so no default needs a `Temporal` polyfill. The project's spec, plan and per-PR specs are in `projects/datetime-convenience-types/`, which is deleted when the project closes. ### 2. Every explicit type names its kind of value (TML-3711) Every type for a column type with more than one codec now carries a suffix, so no explicit type looks like the neutral default and the bare names are free for the convenience types: - `Timestamptz` becomes `TimestamptzTemporal`, `Timestamp` becomes `TimestampTemporal`, and `Interval` becomes `IntervalParts`; - `DateTemporal` and `TimeTemporal` are added beside `Date` and `Time`, which the convenience types take over in prisma#30847. The old names are removed outright; there are no deprecated aliases before the release candidate. Three codecs are added: `pg/timestamp-date@1` (`TimestampJsDate`) and `pg/timestamp-instant@1` (`TimestampInstant`) read a `timestamp` column as UTC, and `pg/interval-string@1` (`IntervalString`) reads an interval as an ISO 8601 duration. Prisma 7's `DateTime` is a `timestamp(3)` read as a `Date`, so an adopted schema needs the first. Temporal fields take their types from `temporal-spec`, a package of declarations with no runtime code. Before, they named the global `Temporal` type and were typed `any` in a project without a polyfill's global declarations. ### 3. String types read ISO 8601 on every server (TML-3418) | `TimestamptzString` holding `2024-01-01T00:00:00Z` | Before | After | | --- | --- | --- | | on a server in UTC | `2024-01-01 00:00:00+00` | `2024-01-01T00:00:00Z` | | on a server set to `Europe/Berlin` | `2024-01-01 01:00:00+01` | `2024-01-01T00:00:00Z` | | holding 44 BC | `0044-03-15 12:00:00+00 BC` | `-000043-03-15T12:00:00Z` | The string codecs return the ISO 8601 form the contract already stores (ADR 254). Codec ids and contracts do not change. Their `now()` generators write the same form and round down to the column's precision. PostgreSQL prints dates in the session's `DateStyle`, so the PostgreSQL target now declares `sessionSettings: { DateStyle: 'ISO' }`, and the driver ensures it on every connection it hands out. A connection Prisma opens gets it as a startup option. A `pg.Pool` or `pg.Client` the application passes in gets `set_config` before first use and again after a connection held for a transaction is released. If a connection still prints another style, every date and time codec fails with `RUNTIME.DATE_STYLE_NOT_ISO` instead of misreading the value. ADR 159 records the rule: a target declares session settings, and the driver ensures them. ### 4. An adopted Prisma 7 schema fills `@default(now())` in UTC (TML-3719) Prisma 7's client filled `@default(now())` itself on create, in UTC, and the database default covered writes from outside Prisma. The Prisma 7 schema reader kept only the database default, so on a server whose `TimeZone` is not UTC every row Prisma 8 created stored local time. The reader now reads `@default(now())` as `@default(now()) @onCreate(now())`. The storage hash is unchanged; the execution hash changes, so adopted projects re-emit. The reader also refuses two schemas Prisma 7 refuses: `now()` on a field that is not a date or time, and a function default other than `dbgenerated` on a list field. ## Testing performed Each part was tested and reviewed in its own PR (see the links above); the details are there. On this branch after combining them: - `pnpm build`, `pnpm typecheck`, `pnpm fixtures:check`, `pnpm lint:deps`, `pnpm lint:ratchets`, `pnpm lint:docs`, `pnpm check:upgrade-coverage --mode pr`. - Package tests and lint for target-postgres, adapter-postgres, driver-postgres, the codec testkit and contract-prisma7, and the date and time integration files and journeys. ## Skill update `skills/prisma-8/references/contract.md` and `debug.md` use the new names, describe ISO values and the `DateStyle` error. Upgrade instructions: `explicit-date-time-types` (`app` and `extension`), the ISO strings instructions (`app` and `extension`), and `prisma7-now-default-on-create` (`app`). ## Checklist - [x] All commits are signed off. - [x] Scoped to one logical concern: the explicit date and time layer the convenience types are built on. - [x] Tests are updated. - [x] The PR title is in `TML-NNNN: <sentence-case title>` form. - [x] The Skill update section is filled in. ## Notes for the reviewer - The three PRs were merged here to send one entry through the merge queue instead of four. Their diffs were approved as they were; the only new work on this branch is the merge of the ISO strings changes with the explicit types changes, which both changed `decodeDate` in `date-codecs.ts`. The shared `decodeDate` keeps the `DateStyle` check, so `TimestampJsDate` and `TimestampInstant` get it too, and `date-style-every-codec.test.ts` checks every registered date and timestamp codec. - Hosted connection poolers (Supavisor, Neon, Hyperdrive, Prisma Postgres, PgBouncer) are not tested. Where a pooler refuses or drops the startup option, the failure is a connection error or `RUNTIME.DATE_STYLE_NOT_ISO`, never a misread value. - SQLite, MySQL and MongoDB convenience types are a later decision (TML-3714), and so are convenience types for other scalars (TML-3715). **Alternatives considered:** - **Name every type after its application meaning, with no explicit layer.** That reverses ADR 257 and leaves arguments as the only exact way to state a column type. - **One codec for `DateTime`, with the column type as a parameter.** A codec represents exactly one data type (ADR 254). - **Keep `Timestamptz` and `Timestamp` unsuffixed.** The explicit types would follow two naming patterns. - **The codecs set `DateStyle`, or the runtime sends `SET` before each query.** A codec has no connection, and a statement per query costs a round trip on every query. - **Parse every `DateStyle`.** The `SQL` and `German` styles are ambiguous for some dates. - **Keep only the database default for Prisma 7's `now()`.** Every adopted project on a server not in UTC keeps a regression from Prisma 7. Agent: sauron-95 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…Duration, and the tools write them (prisma#30847) ## Linked issue Fixes TML-3712 and TML-3713. Part of the Convenience date and time types project (TML-3709). The tools work was reviewed as prisma#30858 and squash-merged into this branch so both reach `main` in one merge-queue entry. ## Summary ```prisma model Order { id Int @id paidAt DateTime // TimestamptzJsDate(3): timestamptz(3), a JavaScript Date settledAt DateTime(as: temporal) // TimestamptzTemporal: timestamptz, a Temporal.Instant legacyAt DateTime(storage: timestamp) // TimestampJsDate(3): timestamp(3), a Date stored as UTC shipBy Date // DateString: date, "2024-02-29" opensAt Time(precision: 0) // TimeString(0): time(0), "09:30:00" period Duration // IntervalString: interval, "P1M" updatedAt DateTime @onCreate(now()) @onUpdate(now()) // the now() generator for TimestamptzJsDate } ``` **The decision: PSL and the TypeScript builder get four convenience types for PostgreSQL, `DateTime`, `Date`, `Time` and `Duration`, and the tools that write a schema for you write them.** Each type is named for what a field means and becomes exactly one explicit type, such as `TimestamptzJsDate(3)`. The contract stores only that explicit type: `paidAt DateTime` emits exactly the column `paidAt TimestamptzJsDate(3)` emits. No default needs a `Temporal` polyfill. ADR 279, on `main` since prisma#30834, is the design. ### Why Prisma 8's explicit types make every choice visible: `TimestamptzJsDate` is a `timestamptz` column read as a `Date`. But each name fixes both the column type and the kind of value, so there are many names and no obvious one to start with. Prisma 8 gives explicit controls first and builds convenience on top of them, as the client facades do for the runtime. These types are that convenience layer for dates and times, and they only help if the schemas users start from, the ones `contract infer`, the Prisma 7 reader and `prisma orm init` write, use them. ### A convenience type is a type choice A type choice is a new kind of type declaration. It declares: - option arguments, each with a fixed set of values written as bare names, and a default: `as:` (the value the application reads: `jsDate`, `temporal`, `string`, `parts`) and `storage:` (the database type); - arguments it hands on to the chosen type, such as `precision:`; - a table from each allowed combination of option values to an explicit type, with any argument defaults for that row. ```ts // @internal/target-postgres: type-constructors.ts DateTime: { kind: 'typeChoice', args: [/* as, storage, precision */], choices: [ { when: { as: 'jsDate', storage: 'timestamptz' }, type: 'TimestamptzJsDate', defaults: { precision: 3 } }, { when: { as: 'temporal', storage: 'timestamptz' }, type: 'TimestamptzTemporal' }, // … ] } ``` A call fills in the default options, looks up the row, and builds the explicit type it names, so bare `DateTime` is its default row. A call is refused at the argument that makes it invalid, and the message lists what that argument accepts: - a value an option does not list, such as `Date(as: jsDate)`; - a combination with no row: `Argument "storage" of Time cannot be timetz with as: temporal; write one of: time.`; - an argument the chosen type does not take, such as `Date(precision: 3)`. When a target's types are loaded, a type choice is refused if it names an explicit type the target does not declare, has two rows for one combination, lists a value or default its option does not declare, or gives a row default for an argument the chosen type does not take. Every place that needs a field's codec resolves the call first, including inside a `types {}` alias: the PSL interpreter, the `@default` value check, the `@onCreate`/`@onUpdate` generator lookup, the Prisma 7 reader, the MongoDB interpreter (which shares the resolution) and the language server. So `DateTime(as: temporal) @onCreate(now())` gets the generator for `TimestamptzTemporal`. ### TypeScript: one object per call `type.DateTime(...)`, `type.Date(...)`, `type.Time(...)` and `type.Duration(...)` take their arguments as one object: `type.DateTime({ as: 'string', precision: 6 })`. Each has one overload per row, so a call is typed as the explicit type it becomes. An unknown key, a combination with no row, an argument the chosen type does not take, and a positional call all fail to compile. Explicit constructors stay positional: `type.TimestamptzJsDate(3)`. ### `DateTime`, `Date` and `Time` change meaning These three names read Temporal values before; that meaning is now `TimestamptzTemporal`, `DateTemporal` and `TimeTemporal`. Every Prisma 8 PostgreSQL schema in the repository that used the old meaning is rewritten to the explicit names, so no committed `contract.json` changes from the rename. The upgrade instruction gives users the same rewrite. ### The tools write the convenience types `contract infer` on this table: ```sql CREATE TABLE event (at timestamptz, paid_at timestamptz(3), legacy timestamp(3), day date, opens time(0), local_at timetz, span interval); ``` writes: ```prisma model Event { at DateTime(precision: 6) // TimestamptzJsDate(6) paidAt DateTime // TimestamptzJsDate(3) legacy DateTime(storage: timestamp) // TimestampJsDate(3) day Date // DateString opens Time(precision: 0) // TimeString(0) localAt Time(storage: timetz) // Timetz span Duration // IntervalString } ``` That schema emits, `db verify` finds nothing, and the planner plans nothing. - **Infer takes the default path, unless that type cannot read the column's own default.** A `timestamp(3) DEFAULT 'infinity'` column becomes `DateTime(as: string, storage: timestamp, precision: 3)`, because a `Date` cannot hold `infinity` and every row created with that default would fail to read. Otherwise, for each column it picks the explicit type the convenience default gives, then writes the shortest convenience call that becomes it, with arguments always by name. It writes the explicit type only when no convenience call fits, such as a `timestamp` read as `Temporal.PlainDateTime` (`TimestampTemporal`). `contract print` writes the same forms. One framework helper builds the call for both, and re-resolves it to prove it gives the same codec and parameters. - **An omitted precision compares equal to 6** on the date and time data types, because PostgreSQL stores microseconds either way. That lets infer write `DateTime(precision: 6)` for a bare `timestamptz` and still verify clean. The planner's check after `ADD COLUMN` still compares the type as written (`catalogParams`). No stored contract or hash changes from this. - **The Prisma 7 reader** maps Prisma 7's `DateTime` to `TimestampJsDate(3)`, printed `DateTime(storage: timestamp)`, and `@db.Timestamptz(p)`, `@db.Date`, `@db.Time(p)`, `@db.Timetz(p)` to the matching convenience forms. An adopted project reads `Date` values where it read strings. - **`temporal.CreatedAt` and `temporal.UpdatedAt`** are built on `TimestamptzJsDate(3)`, exactly bare `DateTime`; their `String` and `JsDate` variants are removed. - **`prisma orm init`** writes `createdAt DateTime @default(now()) @onCreate(now())` and `updatedAt temporal.UpdatedAt`, in PSL and TypeScript. ### Two fixes the default path needs **A `Date` cannot hold digits below a millisecond.** ADR 254 says a codec refuses a stored value its application value cannot hold exactly; the `Date` codecs dropped the extra digits instead. The PostgreSQL `timestamptz` and `timestamp` `Date` codecs and MySQL's `datetime` `Date` codec now refuse such a value in `fromDataTypeValue`, so a `.123456` default on a `DateTime` field is refused at authoring. Rows still read with the digits dropped. Infer prints a microsecond default as its raw SQL expression, and the Prisma 7 reader writes one through its target binding (`refusedLiteralDefault`). `db verify` cannot see a difference below a millisecond on a `Date` column; the docs say so. **`now()` rounds down to the column's precision.** On a `timestamp(0)` column, `now()` at `23:59:59.700` generated a value PostgreSQL rounds up, so the row stored a time later than the write, on the next day at midnight. The PostgreSQL `now` generators for every timestamp codec (`Date`, Temporal and string) now take the column's `precision` and round down, as the time generators already did. Contracts with these generators get a new execution hash; the storage hash does not change. ### Smaller changes - The missing-Temporal error (`RUNTIME.TEMPORAL_UNAVAILABLE`) points to the convenience defaults, and the error reference lists every Temporal codec. - Hover on a convenience call names the explicit type that call is (`DateTime(as: temporal)` is exactly `TimestamptzTemporal`), shows each argument's values, and lists which explicit type each combination becomes. - The glossary defines "explicit type", "convenience type" and "type choice"; ADR 254, 257 and 275 carry notes pointing to ADR 279. ## Testing performed - `pnpm build`, `pnpm typecheck`, `pnpm fixtures:check`, `pnpm lint:deps`, `pnpm lint:ratchets`, `pnpm lint:docs`, `pnpm check:error-reference`, `pnpm check:upgrade-coverage --mode pr`. - Package tests with coverage and lint: framework-components, psl-parser, contract-psl, contract-ts, family-sql, contract-prisma7, MongoDB contract-psl, language-server, target-postgres, adapter-postgres, driver-postgres, target-mysql, CLI and the postgres facade. - Type tests for every row of each table, and negative type tests for each refused call shape. - Integration, run locally because PR CI skips it: every integration file about defaults, generators, dates or times, `test/sql-orm-client`, psl-print, psl-infer, contract-parity, prisma7-source, and the infer, Prisma 7, init and convenience-types journeys. A journey reads every convenience default from PostgreSQL in a process with no global `Temporal`. A PGlite test checks that `now()` at precision 0, 1 and 2 stores the value the client holds. - `contract infer` on the table above writes that schema, which emits, verifies clean and plans nothing. `examples/prisma7-adoption` tests. ## Skill update `skills/prisma-8/references/` (contract, debug, errors, quickstart) describe both layers and what infer writes. Upgrade instructions: `convenience-date-time-types` (the PSL and TypeScript rewrites for the names that change meaning) and `tools-write-convenience-types` (re-emit and `db sign` adopted projects and read `Date` where strings were read; rewrite the removed alias variants; write a sub-millisecond default on a `Date` field another way; re-emit for the `now()` precision). Each has a detection test. ## Checklist - [x] All commits are signed off. - [x] Scoped to one logical concern: the convenience date and time types, and the tools writing them. - [x] Tests are updated. - [x] The PR title is in `TML-NNNN: <sentence-case title>` form. - [x] The Skill update section is filled in. ## Notes for the reviewer - Since the last review, the options are `as:` and `storage:` (they were `value:` and `column:`), and the TypeScript helpers take one object (they were positional). "Value" already means a data type's stored value in ADR 254, and `column` is a SQL word where a convenience name must mean the same on every target. - prisma#30858 was approved before it was folded in; after that approval it gained the rename, the `now()` precision fix, the missing-Temporal error text and the upgrade table's ISO wording. - Merging main's removal of field presets: the refusal for a removed date or time preset names the convenience call that stores what the preset stored, such as `DateTime(as: temporal) @onCreate(now())`, with a `?` or `[]` right after the type. The `option` argument kind remains only for type choices. - Ten Prisma 7 fixtures changed codec and hash; `examples/prisma7-adoption` reads a `Date`. - SQLite, MySQL and MongoDB convenience types are TML-3714; other scalars are TML-3715. **Alternatives considered:** - **A select template over option arguments** (the field-preset machinery). It has no defaults and no way to refuse a combination. - **One codec parameterized by column type.** A codec represents exactly one data type (ADR 254). - **Keep the Temporal meanings and give the convenience types new names.** Then `DateTime`, the name every Prisma 7 user writes first, would be the one that needs a polyfill. - **Options named `value:`/`column:` or `jsType:`/`dbType:`.** See the first reviewer note; `jsType:` and `dbType:` read as jargon. - **Infer writes the string types for microsecond columns, which lose nothing.** The schema would differ from what a user would write. - **Store an omitted precision as 6 in the contract.** It would change existing contracts and hashes; comparing in normal form changes none. Agent: sauron-95 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…l retro, the renames' exception recorded in ADR 257, follow-ups filed (prisma#30895) ## Linked issue Closes TML-3709, the project ticket of the Convenience date and time types project. Every slice has merged: prisma#30834 (ADR 279, ISO strings, explicit types, Prisma 7 `now()`) and prisma#30847 (the convenience types, and the tools that write them). ## Summary ```prisma model Order { paidAt DateTime // exactly TimestamptzJsDate(3): a JavaScript Date settleAt DateTime(as: temporal) // exactly TimestamptzTemporal shipBy Date // exactly DateString: "2024-02-29" } ``` That is what the project shipped: one PostgreSQL type per concept, each meaning exactly one explicit type, with defaults that need no Temporal polyfill. This PR closes the project. It lands the final retro, records the one decision that had no home yet, removes the last link into the project folder, and deletes the folder. ### The retro's lessons The retro entry is in `drive/retro/README.md`. Three lessons became new failure modes in `drive/calibration/failure-modes.md`, two of them with a new item in the slice DoD (`drive/calibration/dod.md`): - **A merge of `main` that resolves an overlapping change is new work** (failure mode F51). The merge of the field-presets removal resolved 42 conflicted files and was sent for review with no review round of its own. The round that followed found twelve defects. The slice DoD now asks for a review of `git diff <main commit> <merge commit>` after such a merge. - **A release bump can archive a pending upgrade instruction while a branch is still editing it** (F52). The branch's edits then land in the released copy. The slice DoD now checks that `git diff <release commit> HEAD -- upgrade-instructions/releases/` is empty. - **When a name changes meaning, check the sources a test emits itself** (F53). `fixtures:check` does not see them, and one such fixture got the PR dropped from the merge queue. The queue also dropped the PR for a journey that `main`'s newest commit changed. The slice DoD already covers that (F44); it was not walked before auto-merge. ### The one decision without a home The project removed `Timestamptz`, `Timestamp` and `Interval` outright, with no deprecated alias, because they were renamed before the release candidate. ADR 257 says a renamed PSL name stays as a deprecated alias for one release line. Its note for ADR 279 now records the exception. ## Project DoD | Item | Verdict | Evidence | | --- | --- | --- | | Every row of the convenience-types table works end to end: emit, `migration plan` DDL, and reading and writing the value type, with and without a global `Temporal` | Met | A close-out journey ran all 13 rows. It covered emit, the planned column types, `db migrate`, then reads in a process with no `Temporal` and in one with the polyfill. Committed coverage: `convenience-types.integration.test.ts`, `convenience-date-time-types-without-temporal.e2e.test.ts`, `temporal-codec-roundtrip.integration.test.ts`. | | `prisma orm init` and a `prisma7Schema(...)` project read `Date` timestamps with no polyfill; a create on a non-UTC server stores UTC | Met | `prisma7-dates-without-temporal.e2e.test.ts` (includes a session in Asia/Tokyo). For init, a close-out run of the PSL starter schema read `createdAt` and `updatedAt` as `Date` with no `Temporal`. The TypeScript starter is checked by type only. | | The research report's use-case table re-run against the shipped surface | Not done | The report is a private artifact that is not in the repository. | | ADR 279 accepted; ADR 254, 257 and 275 carry notes; `scalar-types.md` describes both layers | Met | All on `main`. ADR 257's note gains the deprecation exception in this PR. | | TML-3714 and TML-3715 stay open with their context | Met | Both in Backlog. | The cross-cutting requirements all hold: - **Same contract either way:** a close-out run emitted a convenience schema and its explicit twin through the CLI. The `contract.json` files were byte-identical, with equal storage, execution and profile hashes. - **Every argument combination is a listed choice or an error at the argument.** - **Every default runs with no polyfill.** - **Strings round-trip on a non-UTC, non-ISO server:** a close-out run against a PostgreSQL 17 server started with `DateStyle='German, DMY'` and `TimeZone='Asia/Tokyo'`. - **Outright renames.** - **Upgrade instructions** for every user-visible change. - **Docs moved with the code.** Every review thread on the six slice PRs (prisma#30834, prisma#30851, prisma#30844, prisma#30839, prisma#30847, prisma#30858) is resolved. **Manual QA:** no slice had a QA plan or QA-run report. The close-out runs above took the user paths against a real PostgreSQL server and found no defects. ## Classification Every tracked file under `projects/datetime-convenience-types/` was transient and is deleted: - **`README.md`:** project orientation only. - **`plan.md` and `handover.md`:** coordination. - **`slices/*/spec.md`:** slice contracts. - **`spec.md` and `design-notes.md`:** each carried decisions, and each decision already has a durable home. ADR 279 records the two layers, the type choice, the four types and their defaults, the option names, the TypeScript one-object helpers, what the tools write, and the alternatives. ADR 254 records the ISO stored form. ADR 159 records that the driver ensures `DateStyle=ISO`. ADR 257's note records the suffix rule, and from this PR the outright renames. `scalar-types.md` covers `temporal-spec` and the missing-`Temporal` error. The non-goals are TML-3714 and TML-3715. Nothing migrated to `docs/`, because the long-lived content went into ADRs and reference docs during the slices. ## References The scan found one link into the folder outside it: `projects/target-named-scalars-sql/README.md` line 5. It also called ADR 279 "Proposed". The link now points at ADR 279, and the word is removed. ## Follow-ups filed - **TML-3765:** the contract package's `missing-property-reads` test fails on Node 26, on `main` too. - **TML-3766:** the telemetry backend's handler test expects `ingestedAt` as a `Date`, but the field reads a Temporal value, on `main` too. - **TML-3767:** resolve a type choice call once per field, not in each reader. - **TML-3768:** refuse two type choices that name the same explicit type. ## Checklist - [x] All commits are signed off. - [x] Scoped to one logical concern: the project's close-out. - [x] The PR title is in `TML-NNNN: <sentence-case title>` form. Agent: sauron-95 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Documentation** * Clarified that stored types with multiple codecs use names suffixed by value kind, while unsuffixed concept names refer to convenience types that resolve to those suffixed types. * Documented that PostgreSQL date and time names changed before the release candidate without a deprecated-alias release, and provided upgrade instructions. Other renamed PSL names remain available as deprecated aliases for one release line. * Updated merge, release-instruction, and test-checking guidance, and added a retrospective covering recent process outcomes. <!-- 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 Opus 5.5 <[email protected]>
Linked issue
Fixes TML-3713. Part of the Convenience date and time types project (TML-3709); stacked on the convenience types PR, #30847. It also merges in the Prisma 7
now()defaults PR, #30839, so the diff shows that change too; review it there.Summary
contract inferon this table:writes:
The decision: the tools that write a schema for you (
contract infer,contract print, the Prisma 7 schema reader andprisma orm init) write the convenience date and time types, choosing the convenience default wherever it fits the column. The schema above emits,db verifyfinds nothing, and the planner plans nothing. ADR 279 ("What the tools write") is the design.Why
The convenience types (#30847) only help if the schemas users start from use them. A schema infer writes should read like one a user would write, and the default path should be the one users see first.
Infer and print write the shortest convenience call
For each column, infer picks the explicit type the convenience default gives, then writes the shortest convenience call that becomes it. It writes the explicit type only when no convenience call does, for example a
timestampread asTemporal.PlainDateTime(TimestampTemporal).contract printwrites the same forms; it compares parameters exactly, so it reproduces a contract byte for byte.One framework helper does this for both, beside the type-choice resolver: given an explicit constructor call, it finds the type-choice row that names it, builds the arguments by name, drops those equal to the defaults, and re-resolves to prove the call gives the same codec and parameters.
A column with no precision compares equal to precision 6
PostgreSQL stores microseconds either way, so the date and time data types now treat an omitted precision as 6 when columns are compared (their normal form). That is what lets infer write
DateTime(precision: 6)for a baretimestamptzand still verify clean. Two things keep the precision as written:ADD COLUMNorALTER COLUMN TYPEcompares PostgreSQL'sformat_typewith the type as written, because PostgreSQL prints a baretimestamptzastimestamp with time zone, nottimestamp(6) with time zone. A SQL data type may declarecatalogParamsfor this; MySQL'sdatetimedeclares none.db verifymessages show a bare column astimestamptz.ADR 254's sentence on that check now says the catalog text is for the type as written. No stored contract, hash or committed plan changes.
The Prisma 7 reader, the aliases and
orm initDateTimebecomesTimestampJsDate(3)(printedDateTime(column: timestamp)), and@db.Timestamptz(p),@db.Date,@db.Time(p)and@db.Timetz(p)the matching convenience forms. An adopted project readsDatevalues where it read strings.temporal.CreatedAtandtemporal.UpdatedAtare built onTimestamptzJsDate(3), exactly what bareDateTimegives; theirStringandJsDatevariants are removed.prisma orm initwritescreatedAt DateTime @default(now()) @onCreate(now())andupdatedAt temporal.UpdatedAt, in PSL and TypeScript.A
Datecannot hold digits below a millisecondA JavaScript
Dateholds milliseconds. ADR 254 already says a codec refuses a stored value its application value cannot hold exactly; theDatecodecs dropped the extra digits instead. Now:timestamptzandtimestampDatecodecs and MySQL'sdatetimeDatecodec refuse, infromDataTypeValue, a stored value with digits below a millisecond, naming the types that hold it. So@default(timestamptz2024-01-01T01:00:00.123456Z)on aDateTimefield is refused at authoring. Reading and writing rows is unchanged: a row with microseconds still reads as aDateat the millisecond.contract inferprints a reported default as a literal only when the codec reads it exactly, as it already does for JSON numbers; a microsecond default is printed as its raw SQL expression, which keeps every digit in DDL.refusedLiteralDefault); the Postgres binding writes'2024-01-02T03:04:05.123456'::timestamp(6)orARRAY[...]::timestamp(6)[]. ADR 252 lists the new binding member.Date,db verifyreads both defaults as the application reads them, so a difference below a millisecond is not reported. ADR 254 andscalar-types.mdsay so.The TypeScript builder cannot write such a default at all:
.default()on aDatefield takes aDate.The framework vocabulary limit goes from 237 to 238
The lint counts target words such as
columninpackages/1-framework. The PostgreSQL TypeScript starter thatorm initwrites lives in the CLI package and now containsfield.column(type.DateTime()); the template is one string, so the occurrence can't be shared with an existing one. The same templates are already counted for the same reason.Testing performed
contract inferon the table above writes exactly that schema; it emits,db verify --strictfinds nothing, the planner plans nothing..123456(checked ininformation_schemaand an inserted row); the Prisma 7tsMicroand listts6lfixtures migrate and verify clean; signed years write SQL PostgreSQL accepts. A PSL.123456default onDateTimeis refused;.123is accepted.timestamptzchecks astimestamp with time zone,timestamptz(6)astimestamp(6) with time zone.examples/prisma7-adoptiontests.pnpm fixtures:check,pnpm lint:deps,pnpm lint:ratchets,pnpm lint:docs,pnpm check:upgrade-coverage --mode pr.Skill update
skills/prisma-8(contract.md, the infer part ofquickstart.md) describes what infer writes. Upgrade instructions inupgrade-instructions/pending/tools-write-convenience-types/app/: re-emit anddb signadopted projects and readDatewhere strings were read; rewrite the removed alias variants; write a sub-millisecond default on aDatefield with a string or Temporal type or asqlexpression. The Prisma 7now()defaults instruction now namesDateTime(column: timestamp).Checklist
TML-NNNN: <sentence-case title>form.Notes for the reviewer
examples/prisma7-adoptionhas a re-emitted contract and a new signed snapshot, and its code reads aDate.Datecolumn fails when a migration is planned, until it is re-authored.Alternatives considered:
db verify. It needs a per-type reader beside the codec, and its first version compared one side at full precision and the other through the codec.Agent: thales-11
🤖 Generated with Claude Code