Repository navigation
TML-3607: Type aliases can set @onCreate and @onUpdate, and the contract stores the real column type instead of the alias name - #30819
Merged
Conversation
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…by it An alias resolves once at its declaration to a column type with its params inline, plus its @default, @onCreate and @onUpdate, lowered for that column. Each field typed by it takes the column type and the lowered attributes. Nothing is written to storage.types and no column gets a typeRef. @id and @unique on an alias are refused with their own message; any refused attribute is dropped and the alias kept. A field that repeats an attribute its alias sets is PSL_DUPLICATE_ATTRIBUTE. A list field typed by an alias that sets a default or a generator is refused. The family-neutral part (base classification, attribute filtering, repeat check, the spec context an alias is read in) lives in @internal/psl-parser so Mongo can reuse it. The @updatedat hint now names temporal.UpdatedAt. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…very PSL type constructor The Postgres and SQLite targets now contribute the PSL scalar and native type constructors, so PSL sees the same names and the TypeScript builder gains type.String(), type.VarChar(64), type.TimestampString(3) and the rest. A type.* helper with no parameters gives a column with no typeParams, as PSL does. The contract types key is now databaseTypes and only registers a database type in storage.types; pgvector and PostGIS use it, and their emitted contracts are unchanged. defineContract refuses a types key with CONTRACT.TYPES_KEY_REMOVED. field.namedType takes only an enum handle. .default() on a field that already has a default throws CONTRACT.DEFAULT_INVALID with reason default-set-twice. The committed TypeScript contracts that used types or field.namedType on a codec instance now write field.column(...) constants. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…emporal.CreatedAt and temporal.UpdatedAt
A pack may contribute a typeAlias in its type namespace: a column type with
fixed params, and the default and generator calls every field typed by it
takes. It takes no arguments. The control stack and the SQL and Mongo
TypeScript builders resolve each alias generator call against the assembled
generator functions through one shared function, and refuse a call that does
not resolve for the alias codec with CONTRACT.PACK_CONTRIBUTION_INVALID.
SQL PSL reads a field typed temporal.CreatedAt through the types {} alias
path: the field takes the column type and generators, may add an attribute
the alias does not set, and repeating one is PSL_DUPLICATE_ATTRIBUTE.
temporal.CreatedAt(3) is PSL_INVALID_ATTRIBUTE_ARGUMENT. SQL TypeScript
gets type.temporal.CreatedAt(); field.column copies its default and
generator calls into the field, which is then optional on create. The
language server completes and hovers an alias as a type with its
documentation.
Postgres contributes CreatedAt and UpdatedAt with String and JsDate
variants, SQLite and Mongo contribute CreatedAt and UpdatedAt. Each stores
what the matching preset stores; none sets a database default. Mongo PSL
still refuses a field typed by an alias.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… into the fields typed by it
A Mongo field typed by a types {} alias, or by temporal.CreatedAt or
temporal.UpdatedAt, takes the alias type and the values its @onCreate and
@onUpdate generate, keyed by the stored field name. Each alias resolves once,
so a generator that does not apply is reported once, at the alias.
MongoDB has no database defaults, so @default on an alias is refused at the
alias with the @onCreate(now()) hint. A field typed by a generating alias is
refused when it is optional, a list, or a composite type member; a variant
field is refused as any generated value is. A field that repeats an attribute
its alias sets is PSL_DUPLICATE_ATTRIBUTE, and a field typed by an alias may
not take arguments.
A bare type constructor keeps its fixed type params. The refusal of @id and
@unique on an alias moves to the shared alias helper, which now takes the
attributes a family accepts. The Mongo @updatedat hint names
temporal.UpdatedAt.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…s branch
StorageColumn and ColumnTypeDescriptor have no typeRef, and the column schema
has no such key. A stored contract whose columns hold typeRef is refused after
the nativeType and noCheck checks, naming the first five columns and pointing
at expand-type-aliases.ts. storage.types keeps its schema and now holds only
the database types a contract space registers. resolvedTypeParams is replaced
by nonEmptyTypeParams, which reads a column's own params.
The emitter writes no typeRef and resolves column types from the column's own
params. The runtime drops ExecutionContext.types, TypeHelperRegistry and the
alias pass of the codec registry, so a parameterized column's codec instance is
named <col:Table.column>, shared by every column with equal params.
codecRefForStorageColumn keeps the list flag. contractToSchemaIR, the Postgres
and SQLite DDL builders, the identity values, reported defaults, the stack
checks and the field event planner read the column alone; the planner no
longer takes storageTypes, and the codec hooks still run for storage.types.
contract print writes no types {} block and refuses a contract that registers
database types. buildContractDefinition and buildSqlContractFromDefinition
refuse a types key with CONTRACT.TYPES_KEY_REMOVED. A SQL PSL field that calls
a types {} alias is refused as calling a type alias, as in Mongo.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ts columns The upgrade script replaces every column typeRef in a stored SQL contract with the referenced storage.types entry's params, removes each referenced entry, keeps and lists entries no column references, and rewrites contract.d.ts, snapshot directories, migrations, refs and migration.ts as remove-nocheck.ts does. The app and extension copies are byte-identical. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s in its columns Ran expand-type-aliases.ts over the examples, the Supabase space contract, the sql-orm-client and ports fixtures, the contract-format fixtures and the postgres-extension-space and sqlite-project fixtures of two earlier upgrade fragments, then re-emitted with pnpm fixtures:emit, which changed nothing further. Tests that pinned old hashes or the stored Supabase aliases now pin the expanded contracts. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…n into its columns The expand-type-aliases fragment lists every consumer change for apps and extensions. ADRs 104, 159, 208, 212, 241, 254 and 275 carry dated amendments; the subsystem docs, READMEs, error reference and the contract skill reference describe aliases as authoring shorthand and databaseTypes as the only storage.types writer. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…scriptor default The type alias descriptor reuses the framework column default types (AuthoringColumnDefaultTemplate, ColumnDefault) at three lines, and the shared alias refusal names a column type as the spec words it, so the threshold rises from 237 to 241. A local variable in type-aliases.ts no longer says column. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…tribute take values of data types Main brought TML-3615, TML-3674 and TML-3604. The type constructors this branch moved to the targets keep main's value arguments, and the target type namespaces keep main's sql.String next to the temporal aliases. contributedHelpers skips type aliases, as contributedConstructors did. The value-object and named-type paths take main's dataTypes. The tests this branch added declare value arguments, and the Postgres interpreter test helper names the fixture text data types. The framework vocabulary threshold stays at main's 237. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…pes as the fixture list Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…he vocabulary threshold stays at 237 Each family supplies the word in the @id and @unique refusal of a type alias: the SQL interpreter says column type, and the Mongo interpreter says field type. A contributed type alias stores its default as the database default a @default lowers to, typed through LoweredDefaultValue, because an alias takes no arguments and so needs no default template. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…, and assembly checks its params and its generators for its length A contributed alias no longer has a database default: no pack sets one, and it was a SQL concept on a framework descriptor. Assembly now checks the alias's fixed type params against its codec's params schema, and resolves its generator calls for the length the family gives those params, so a broken pack is refused with CONTRACT.PACK_CONTRIBUTION_INVALID before a schema is read. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…alias, and one sentence refuses @id and @unique on it in both families The refusal of @id and @unique no longer needs a family word, so the typeNoun parameter goes. The diagnostic codes keep their names. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…abaseTypes, as defineContract does Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…hat they hold, since they feed PSL and TypeScript alike ADR 241 now says the target contributes them, so they are also type.* helpers. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s and ResolvedTypeAliases, as the SQL resolver does Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…input Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…efore two snapshots become one In the app's own contract space the script now removes every storage.types entry no column references, so an alias the source declares but nothing uses leaves the contract as a re-emit does. It keeps such entries only in an extension's space, which it tells by the migrations directory that names the snapshot. Before writing, it stops when a migration or ref names two snapshots that become the same one, and names the migration between them. Tests cover both, and the three stop cases that had none. The instructions run the script, re-emit, then sign. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…de script wrote and a re-emit of its source 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]>
…tops before two snapshots become one Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…data operation, keeps the entries of unnamed snapshots, and lists what it removed Two snapshots that become one stop the script only when a migration between them has no operation of class data, the rule the migration checker uses. The stop says only to delete that migration directory and run again; the next run rewrites every reference and migrationHash. A snapshot that no migration or ref names keeps its unreferenced storage.types entries. The summary lists every storage.types entry the script removed, per contract. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…try, and an extension author to re-emit, publish and have apps sign An app's own contract space never needs a registered database type, so the TypeScript section tells a user to delete a codec-instance entry no field uses and to write a used one as a field.column constant. The guides describe the narrowed stop for two snapshots that become one, the unnamed snapshot rule and the removed-entries summary. The extension guide says what to do when a re-emit changes the bundled storage hash. Spec D11 gives the corrected reasons. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ases are tested A Postgres TypeScript contract with an extension that contributes a type alias is refused when the generator does not fit the column length or the codec refuses the fixed params. The Mongo builder is refused when the codec refuses the fixed params. Each test fails when its lookup is replaced by one that returns undefined. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ma, the refusals, TypeScript, MongoDB and the language server through the CLI Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…gration it says to delete, and stops naming an ops.json that does not parse When a migration between two snapshots that become one is the app's latest, nothing else names its target snapshot, so the stop line now names that snapshot directory to delete too. A migration whose ops.json is not valid JSON gets the not-valid-JSON stop instead of advice to delete it. The merge tests move to their own file and cover keeping an existing merged directory and merging two changed snapshots after an alias rename. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…n a re-emit drops an unused alias, so the head ref names the bundled contract The script keeps an unused alias in an extension's space, and each application gets that hash for its copy of the extension's migrations. When the re-emit drops the alias, the author now writes a migration with no operations from the head hash to the re-emitted hash, adds its snapshot and moves the head ref, instead of publishing a bundled contract the head ref does not name. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…lias, and say what to write instead An alias written as another alias says what to write: the other alias's type constructor and attributes, or, for a contributed alias, to type the fields with it or write a type constructor with its generator attributes. A list field typed by a generating alias names the alias in SQL, as it already did in MongoDB. The TypeScript phase refusal, the MongoDB write-time refusals and the registry collision message no longer call an alias a field preset. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ompletion tells the String and JsDate variants apart temporalTypeAliases takes the TypeScript value the codec gives and ends each alias's documentation with it: a Temporal.Instant, a string as Postgres writes it, or a JavaScript Date. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…, and how an extension handles an alias a re-emit drops 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]>
…eds in the descriptor, and to import the extension's own target's migration module Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…the script, and that this is expected Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…chain, suggests nothing for a cycle, leaves out comments, and names the type constructor of a contributed alias The suggested line is built from the syntax nodes of the type and attributes, so a comment no longer swallows an attribute. A chain is followed to its first base that is not an alias, with the attributes of every alias in it. For a contributed alias, the line names the first type constructor of the stack that gives the alias's type, such as X = DateTime @onCreate(now()) @onUpdate(now()) on Postgres. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
|
Important Review skippedToo many files! This PR contains 379 files, which is 79 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: 25
📒 Files selected for processing: 379
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 📦
|
wmadden
approved these changes
Oct 21, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 21, 2026
…s to print as its type constructor, with no types block
contract print writes no types {} block now that contracts store no alias, so the raw-columns and extension-types round-trip tests assert the expanded column instead of the alias declaration.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… the migration tooling wrote, so the data-type-in-contract script's output matches the after tree Biome sorted the imports of the before migration.ts by snapshot hash when the fixture's hashes changed. The script keeps import order, and the new hashes sort the other way, so its output no longer matched the sorted after tree. Biome no longer organizes imports in the migration.ts files of upgrade fixtures, and the before file is back in Start, End order. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden
enabled auto-merge
October 21, 2026 16:21
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Oct 27, 2026
…constructor or type alias that stores the same contract (prisma#30845) ## At a glance Before this PR, a Prisma 8 schema could write a field with a *field preset*, a single call that set the column type, the identity and the generated values at once: ```prisma model User { id id.ulid() updatedAt temporal.updatedAt() posts Post[] } model Post { id id.ulid() authorId ulid() author User @relation(fields: [authorId], references: [id]) } ``` After this PR, field presets no longer exist. The same fields are written with the type constructors, type aliases and attributes the rest of a schema already uses: ```prisma model User { id Ulid @id @onCreate(ulid()) updatedAt temporal.UpdatedAt posts Post[] } model Post { id Ulid @id @onCreate(ulid()) authorId Ulid author User @relation(fields: [authorId], references: [id]) } ``` `Ulid` is a new type alias for `Char(26)`, the column a ULID is stored in. The id and the foreign key use the same alias, so nobody writes the length 26. The new form stores exactly the same contract, so the storage and execution hashes do not change. A user only rewrites the calls; nothing is re-emitted, signed again or migrated. The same holds in TypeScript: `field.id.ulid()` becomes `field.column(type.Ulid()).id().onCreate(gen.ulid())`. ## The decision ADR 275 decided to remove field presets. This PR, the third and last for TML-3607, carries that out: - **Earlier PRs:** prisma#30780 made generated values attributes (`@onCreate`, `@onUpdate`), and prisma#30819 let type aliases carry those attributes, adding the ready-made aliases `temporal.CreatedAt` and `temporal.UpdatedAt`. - **This PR:** with replacements in place, it removes the presets themselves, in PSL, in both TypeScript builders (SQL and MongoDB), and in the framework. Presets were a second way to write what attributes already say, with their own argument forms such as the bare `now` in `onCreate: now`. Their authors also paired a column codec with a generator by hand, which once wrote a JavaScript `Date` into a text column. Attributes and aliases cover the same ground, and any user can write them. ## A type alias for each generated identifier Identifier presets were the main reason presets existed: a user wrote `id.ulid()` and never needed to know a ULID is stored in `Char(26)`. So this PR adds a type alias for each identifier column. ADR 310 explains the design. | Alias | Stands for | A generating field writes | |---|---|---| | `UuidString` | `Char(36)` | `@onCreate(uuid())` or `@onCreate(uuid(7))` | | `Ulid` | `Char(26)` | `@onCreate(ulid())` | | `Nanoid` | `Char(21)` | `@onCreate(nanoid())` | | `Cuid2` | `Char(24)` | `@onCreate(cuid(2))` | | `Ksuid` | `Char(27)` | `@onCreate(ksuid())` | - **The alias names the column only.** A foreign key holds a copy of the id, so it needs the same column and must not generate a value. The id field writes `@id` and its generator itself. - **Where the names live.** The SQL family provides them as `sql.Ulid` and so on, on Postgres, SQLite and MySQL. Postgres also has them as top-level names, like its other column types `Char` and `Uuid`. In TypeScript they are `type.Ulid()` and `type.sql.Ulid()`. - **A one-word id is a mixin the user writes:** `model mixin UlidId { id Ulid @id @onCreate(ulid()) }`, then `+UlidId`. The upgrade guide shows it, with the TypeScript constant `const UlidId = field.column(type.Ulid()).id().onCreate(gen.ulid());`. - **Native UUIDs need no alias.** On Postgres, `Uuid @id @onCreate(uuid(7))` is the recommended form, and the `prisma init` Postgres TypeScript starter now uses it. ## What a user sees **PSL refuses every preset with its exact rewrite.** For example: ```text PSL_UNRESOLVED_REFERENCE: id.ulid() was a field preset, and Prisma 8 removed field presets. Write Ulid @id @onCreate(ulid()). ``` On SQLite the rewrite is `sql.Ulid @id @onCreate(ulid())`. On Postgres, a schema that declares its own `model Ulid` gets the `sql.Ulid` form, because its model hides the top-level name. **The refusal is shown in a schema with relations.** Before, a field whose type did not resolve was dropped, and the contract build then threw a relation error, such as `CONTRACT.RELATION_INVALID: Relation "User.posts" joins on column "id" ...`, which hid the real diagnostic. Now field resolution records every field it drops, and the build stops before it runs. The user sees the refusal with its rewrite. This applies to any unresolved field type, not only presets. **An unknown bare type name suggests the name in a namespace.** On SQLite, `Ulid` gives `Cannot find type "Ulid". Did you mean sql.Ulid?`. **TypeScript refuses a preset twice.** It is a compile error, because the helper no longer exists. If a contract still calls one at run time, for example through `contract emit` before `tsc`, the read throws `CONTRACT.FIELD_HELPER_UNKNOWN` with the same rewrite. Before this, the user got `Cannot read properties of undefined`. The run-time check answers only the removed preset names and adds nothing to the public types. **An extension that still contributes presets is refused.** A pack with an `authoring.field` namespace fails with `CONTRACT.PACK_CONTRIBUTION_INVALID`, and the message says to contribute a type alias instead. **A new SQL type constructor, `sql.Char(length)`, on every SQL target.** SQLite stored its identifier presets as a fixed-length text column but had no way to write that type. Now `sql.Char(36)` works on Postgres, SQLite and MySQL. **The upgrade guide** is `upgrade-instructions/pending/remove-field-presets/`, for apps and for extension authors. It has a before-and-after table for every preset in every target and both TypeScript builders. It opens by saying which advice from the 8.0.0-rc.19 guide no longer holds. ## What was removed - The `fieldPreset` descriptor kind, the `authoring.field` namespace, and every preset map in the SQL family, Postgres, SQLite and MongoDB. - `field.generated(...)` and the `@internal/ids` helpers that bundled a column type with a generator. - The `option`, `number` and `object` argument kinds, the `select` template, and the two text parsers only those used. Only the `value` argument kind remains. - The preset branches of the language server. - The `projects/remove-field-presets/` folder, now that the project is done. Its long-lived content moved into ADR 275's amendment, ADR 310 and the Data Contract doc. ## How it was checked - **Same contracts.** A parity test runs every preset (on Postgres, SQLite and MongoDB) through the real emit pipeline and checks that its replacement stores the same contract. For PSL, it takes the rewrite from the refusal message itself and checks that. For TypeScript, a sibling test does the same for every rewrite. Another test checks that a key and a foreign key typed by each alias emit the same contract as `Char(n)`. `fixtures:check` shows no contract change across the repository. - **Real upgrades by hand.** Projects that used presets, on Postgres and MongoDB in PSL and TypeScript, were upgraded by following the guide, and came out with the old hashes. Manual QA of the aliases ran the built CLI on Postgres and SQLite projects: each alias in every form, the refusals with and without relations, the length check, TypeScript type checking, `prisma init`, `contract print`, and every example in the guide. - **New projects.** Each `prisma init` starter writes no preset, and a test pins its contract hashes. The Postgres TypeScript starter's storage hash changes, because its ids move to the native `uuid` column. This affects only new projects. - **Review.** Six rounds of `/drive-code-review` and two rounds of manual QA; every in-scope finding is fixed. - **Checks.** Every CI lint step and coverage pass, along with all related integration files, run one at a time. - **Examples.** Merging main's renamed Postgres date and time types (`TimestamptzTemporal`, `TimestampTemporal`) broke two files in `examples/prisma-8-demo`. They are updated with the rename only. The framework vocabulary check counts SQL and MongoDB words inside `packages/1-framework`. This PR lowers that count from 236 to 218. It adds two counted lines: the `prisma init` templates now write `field.column(...)`. Those templates were already SQL code inside the framework CLI. Moving them out needs a new framework interface, which is TML-3702. ## Follow-ups - **TML-3702:** move the `prisma init` templates out of the framework CLI. - **TML-3705:** a contributed type alias cannot take arguments, so `temporal.UpdatedAt` has no form with a precision, and a nanoid of another size has no alias. - **TML-3706:** the MongoDB TypeScript builder has no `type.*` helpers, so it cannot use contributed aliases. MongoDB TypeScript users write `field.date().onCreate(gen.now()).onUpdate(gen.now())`. - **TML-3707:** generator descriptors share a structure with the default functions, which leaves five empty registries. - **TML-3751:** the rule that decides whether a rewrite applies on a target is written twice, once for PSL and once in the SQL TypeScript package, because that package cannot import the PSL parser. - **TML-3752:** a model named like a type, such as `model Ulid { id Ulid @id }`, fails with an error that does not mention the name clash. - **TML-3753:** a TypeScript contract that was never type-checked and uses a name its target lacks, such as `type.Ulid()` on SQLite, fails with a raw `type.Ulid is not a function`. - **TML-3754:** the "Did you mean" suggestion lives in the SQL family's unresolved-type hook, so MongoDB schemas do not get it, and it does not cover calls such as `Foo(3)`. ## Alternatives considered - **Keep presets as a shorthand beside attributes.** Not chosen: two ways to write one thing, and presets were available to packs only, not users. - **An identifier alias that carries the generator too.** Not chosen: a foreign key needs the same column without a generator, so each format would need two aliases. ADR 310 covers this and the naming alternatives. - **TypeScript stubs that throw when called.** Not chosen: they would keep every preset name in the public types. The run-time check answers removed names only, through the object, and the types stay clean. - **Move the `prisma init` template text into files the vocabulary check skips.** Not chosen: that would hide the lines from the check without moving the SQL code out of the framework. TML-3702 tracks the real move. Closes TML-3607. Agent: frankenstein-64 --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[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
After this PR, a Prisma 8 schema can define a reusable type once and give it generated values:
UpdatedAtis a type alias, a name forTimestampString(3). Any field typedUpdatedAtgets that column type and the current time on create and on every update.temporal.CreatedAtis a type alias that Postgres provides, so users do not have to write their own.Until now, an alias could not carry
@onCreateor@onUpdate. The only way to say "set this timestamp on every update" was a field preset such astemporal.timestampString(3, onCreate: now, onUpdate: now).The decision
A type alias is a shorthand in the schema file, and the contract does not store it. When Prisma reads the schema, each field typed by an alias gets the alias's type and attributes, exactly as if the user had written them on the field. The contract then records the column's real type. It no longer records the alias name.
So for this schema:
The contract used to store the alias, with a column that only pointed at it:
It now stores the column alone:
This is the second of three PRs for TML-3607, which carries out ADR 275. The first, #30780, made generated values attributes (
@onCreate(uuid())instead of@default(uuid())). This one makes aliases able to replace field presets. The third will remove field presets.Why
The contract describes the database. An alias name exists only in the schema file: renaming
SlugtoShortTextchanges nothing in the database, but it changed the contract's hash, so users had to sign their database again. Nothing in the runtime reads the alias name.Aliases were stored because PSL once had no way to write a type with its parameters inline, such as
VarChar(64). It has that now, so the alias can be resolved when the schema is read.Once aliases can carry
@onCreateand@onUpdate, they cover what field presets were for: a reusable column type with generated values. Unlike presets, any user can write one.What users get
Aliases with generated values. An alias may set
@default,@onCreateand@onUpdate. A field typed by the alias may add attributes the alias does not set. Prisma refuses the following, each with a message that says what to write instead:@idor@uniqueon an alias, because those describe a model's field, not a type;Ready-made timestamp aliases. Postgres, SQLite and MongoDB each provide
temporal.CreatedAt(the time a row is created) andtemporal.UpdatedAt(the time it is created and every time it is updated). Postgres also hasStringandJsDatevariants, for the other ways it can return a timestamp. Each one stores exactly what the matching field preset stores today. So the third PR can remove the presets without changing any user's contract. The editor completes these names and shows their documentation.MongoDB schemas can use aliases. Before, MongoDB refused any field typed by an alias.
The same in TypeScript. An alias is a constant:
type.*now has a helper for every type PSL can write, such astype.VarChar(64). Thetypeskey indefineContract, which declared aliases, is removed. Using it is an error that says what to write instead.What users must do
Every contract that uses a
types {}block gets a new storage hash, because its columns change shape. The PR ships an upgrade script,upgrade-instructions/pending/expand-type-aliases/.prisma db sign.Without the upgrade, Prisma refuses a stored contract that still holds an alias, and the error names the script.
Extension authors have a separate guide in the same folder.
How it was checked
main's demo apps, it produced this branch's migrations. Its tests run Prisma's own migration checker on the result.mainand then upgraded with this branch by following the guide.prisma db verifyreports no issues. The report isprojects/remove-field-presets/manual-qa-reports/2026-10-21-slice-2.md./drive-code-review, all findings fixed. All repository checks pass.Decisions ADR 275 left open
vector,geometry) through the removedtypeskey, and PSL cannot write that. They now use a new key,databaseTypes, which means only that. Their contracts do not change.Date, because MongoDB'sDateTimeis deprecated.type.*helpers to build them on. MongoDB TypeScript users writefield.date().onCreate(gen.now()).onUpdate(gen.now()). This is recorded inprojects/remove-field-presets/deferred.md.ADR 275 and the ADRs it changes carry dated notes on these points.
Alternatives considered
typesfor extensions. Not chosen: every existingtypeskey in a user's app holds aliases, and would silently become a declaration of database types.TML-3607 stays open until the third PR merges.
Agent: frankenstein-64