GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — TML-3607: Client generators are written @onCreate and @onUpdate, and @default means a database default by wmadden-electric · Pull Request #30780 · prisma/orm Conversation
Contributor
A value the client generates is now written as an attribute that names the phase, and model Event { id String @id @onCreate(uuid(7)) code VarChar(32) @onCreate(nanoid()) createdAt DateTime @default(now()) @onCreate(now()) seenAt Time(3) @onUpdate(now()) } Before, id: field.column(uuidColumn).id().onCreate(gen.uuid(7)), seenAt: field.column(timeColumn(3)).onUpdate(gen.now()), This is slice 1 of three for TML-3607, as ADR 275 decides. The project spec and the slice plan are in What changedA registry of generator functions. Each function name (
TypeScript. The Prisma 7 and Prisma 6 readers resolve
Field presets still work in this slice. Slice 2 expands type aliases into each column. Slice 3 removes presets. Upgrading
How it was checked
Alternatives considered
Closes nothing yet: TML-3607 closes with slice 3. Agent: pele-26
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThe project spec groups the requirements of ADR 275 by area. The plan splits the work into three PRs: generator attributes, alias expansion, and preset removal. The slice 1 spec gives the code changes, decisions, tests and docs for the generator attributes. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …et bindings The framework holds the registry shape and assembly. The SQL family declares now, uuid, cuid, ulid, nanoid and ksuid and binds the identifier functions to its char, varchar and text codecs. Postgres binds now to its date and time codecs and the identifier functions to its text-like and uuid codecs; SQLite and Mongo bind their own. The control stack assembles the registry and checks every binding against the generators the stack registers. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Both families register the two attributes in their attribute-spec namespaces. Each offers only the generator functions bound to the field codec, and the interpreters resolve the call through the stack registry with the column type parameters. The registry reaches the binder, the interpreters and the language server through the contract source context. A call that the codec does not bind, an unknown function, a list field, and a phase a field preset already sets are refused; Mongo also refuses an optional field. The @updatedat hints name the attribute form. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …nUpdate Print writes each generator as the call of the generator function the stack binds to the column codec, after any @default, and checks that the call resolves back to the stored generator. It now writes on-update generators and a generator beside a database default, which it refused before. The field preset print search, the default function printers and their refusals are removed, since print was their only user. The slugid parity pack contributes a generator function. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …h the registry The Prisma 7 reader resolves @updatedat as now() for both phases and the client functions in @default as onCreate through the generator function registry, and keeps database functions on the default function registry. The Prisma 6 Mongo reader resolves @updatedat and @default(now()) the same way. Prisma7TargetBinding.updatedAtGenerator and Prisma6TargetBinding.timestampGeneratorId are removed. The contracts both readers build do not change. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …eeps Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …ypeScript builders A field builder takes a call from gen, such as gen.uuid(7) or gen.now(), and the call is resolved by the column codec and type params through the generator functions of the family, target and extension packs when the contract is built. .onCreate makes the field optional on create; .onUpdate alone does not. Setting a phase twice, or a phase a preset already sets, throws CONTRACT.DEFAULT_INVALID. The SQL, Mongo and facade contract-builder entries export gen. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> The app fragment ships a script that rewrites @default(uuid()), @default(cuid(2)), @default(ulid()) and @default(nanoid()) to @onCreate in the Prisma 8 schema files it is given, and leaves a Prisma 7 schema unchanged. The extension fragment says how a default function that generated a value becomes a generator function. The pending contract-print-generated-values fragment, whose printArguments guidance this change removes before release, now points to the new fragment. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …same hashes Each Postgres date and time preset field and the Mongo temporal preset fields get a twin written with type constructors and @onCreate(now()) @onUpdate(now()). The twins emit the same storage and execution hashes as the presets they replace. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> The default function registries keep autoincrement and now. A default function can no longer lower to a client generator, and @default(uuid()), @default(cuid(2)), @default(ulid()) and @default(nanoid()) are refused with PSL_GENERATOR_IN_DEFAULT, whose message names the @onCreate form. applicableCodecIds and buildPhases are removed from generator descriptors, since bindings declare the codecs a generator fills. Every Prisma 8 schema, inline test schema and doc example that wrote a client function in @default now writes @onCreate. The emitted contracts do not change. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> ADR 275 is accepted, with its nanoid rule limited to fixed-length columns and the break for extension default functions recorded. ADRs 158, 169, 231, 249 and 269 are amended. The error reference lists PSL_GENERATOR_IN_DEFAULT, PSL_UNKNOWN_GENERATOR_FUNCTION, PSL_GENERATOR_NOT_APPLICABLE and PSL_LIST_EXECUTION_DEFAULT_UNSUPPORTED, and the TypeScript generator reasons of CONTRACT.DEFAULT_INVALID. The subsystem docs, package READMEs, the contract skill reference and the PSL scorecard describe @onCreate, @onUpdate and gen. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …n against the family signatures The framework is family-blind, so a generator resolves for a GeneratorFunctionField, a column in SQL and a document field in Mongo, instead of a column. The framework vocabulary threshold drops to the new count. A test checks that every gen helper passes only the argument keys of its SQL family signature and resolves on a column the function binds. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …fixture Its recording differs from the now fixture only in the contract path. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …very stack The generator function vocabulary has one home in @internal/framework-components/components, with one call type, GeneratorFunctionCall, and BindingResolution for a binding result. gen is built from the composed family, target and extension packs like the type helpers, so each stack holds exactly its functions; the closed framework list and its parity test are gone. The generator descriptors move from the adapters to the target pack refs, so every stack, both TypeScript builders included, checks that a binding produces a registered generator, and resolve refuses a generator id a binding does not declare. ContractSourceContext.generatorFunctions is required. nanoid never takes its size from the column; a size that does not fit a Char or VarChar column is refused. The SQL builder refuses a generator on a list field, PSL refuses a repeated @onCreate or @onUpdate, and Mongo refuses an optional generated field with PSL_OPTIONAL_EXECUTION_DEFAULT_UNSUPPORTED. The print logic that turns generators into calls moves to the SQL family. Tests cover the real Postgres bindings, the language server config path, parity through the facades and an extension, and a print round trip of the slice example. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> … header The upgrade script now rewrites a file only when its first line is // use prisma-8 or the older // use prisma-next, and prints a line for each file it skips. A Prisma 7 schema split across files keeps @default(uuid()) in its model-only files. The tests add a model-only Prisma 7 file, a file with the older header and a commented call. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> … refusals ADR 275, the project and slice specs and the READMEs say that nanoid never reads its size from the column and that gen is built from the composed packs. The error reference adds PSL_OPTIONAL_EXECUTION_DEFAULT_UNSUPPORTED, PSL_DUPLICATE_ATTRIBUTE and the generator-on-list reason. The extension upgrade guide imports from the components entry and asks for generator descriptors on the pack ref. The plan adds the preset names that slice 3 renames, and deferred.md records that default functions still live on the adapters. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> generator-calls.ts was left out of the previous commit by a file filter, so the tip did not build. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> The Mongo target pack ref named its fields without generatorFunctions, so the Mongo gen was typed {} and gen.now() did not type-check. Each facade now takes gen from the same packs as its defineContract: Postgres from the one composed helpers call that gives field, SQLite and Mongo typed by their builder helper types. Type tests check the exact functions of each facade gen and refuse a wrong argument. The Mongo target registers timestampNow as the SQL targets do, without a /control import.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The component that contributes a binding registers its generator ids. The SQL family registers uuidv4, uuidv7, cuid2, ulid, ksuid and nanoid, so a SQL target that binds them through idGeneratorFunctionBindings registers none. Postgres and SQLite register only their now generators and no longer depend on @internal/ids. GeneratorPhase is defined once, and the family call text is named PhaseCallText. The planner manifest records the time parity contract. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …arkers gen passes arguments by position, so assembly refuses a generator function signature with named parameters. The argument output marker gen reads is defined in the components entry, and psl-parser ArgTypeOutput extends it. ExtensionPackValues and GeneratorPhase have one definition in the components entry, and the ComponentMetadata doc says pack refs carry generator descriptors. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> … the column refuses @db.Char(10) @default(nanoid()) is refused with PSL.PRISMA7_GENERATOR_REFUSED, since Postgres refuses such an insert. It was PSL.PRISMA7_UNKNOWN_DEFAULT. The README lists it as the one shape main read that the reader now refuses. The test support drops a dead fallback. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …grade script The script uses the directive rule of isPrismaNextSchema over the whole text, so a blank line or a byte order mark before the directive, //use prisma-8 and text after it are all read as Prisma 8. The language server integration test passes clientSupportsSnippets. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> The slice spec says the SQL family registers the identifier generators and that named parameters are refused, D3 and D11 record the Prisma 7 nanoid refusal, and the error reference adds PSL.PRISMA7_GENERATOR_REFUSED. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> The script checks generator attributes through the real CLI on Postgres, Prisma 7, the TypeScript builder and MongoDB, plus the upgrade script. Every step passed; the report lists six minor observations. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> assembleControlMutationDefaults and assembleGeneratorFunctions share one check, so contract emit and the TypeScript builders both refuse a repeated generator id with CONTRACT.PACK_CONTRIBUTION_INVALID, naming the id and both components. It was an InternalError on the control stack and accepted by the builders. The extension guide tells a target, adapter or extension that registers the identifier generators the SQL family now registers to stop, with a detection for it. A test pins the family ids to builtinGeneratorIds, and the unused builtinGeneratorRegistryMetadata is removed. psl-parser builds its optional marks on the shared SignatureOptionalArgument. deferred.md records the five empty default function registries. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> PSL.PRISMA7_GENERATOR_REFUSED quotes the call from the source, so cuid() stays cuid() and spaces are kept. The README says main read the Char(n) form and refused the VarChar(n) form under another code. A VarChar case is tested. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> …s own code A TypeScript builder refusal such as CONTRACT.DEFAULT_INVALID reached the CLI wrapped in CONTRACT.SOURCE_LOAD_FAILED with a generic hint, and --json lost its code and reason. It is now reported as it is, as errorFromCaught does for other commands. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> The upgrade script no longer rewrites or counts @default calls in // comments, keeps the call exactly as written and changes only the attribute name, and says "1 @default call". A test checks that it treats a file as Prisma 8 exactly when isPrismaNextSchema does. 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]> …erators The upgrade script rewrites calls only in code, outside string literals and comments, so @default("x @default(uuid()) y") keeps its value. The extension detection also matches double-quoted ids, and its summary lists the repeated-registration refusal. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> … in the docs ControlClient.emit keeps the code and meta of a structured error the source throws, with its message as summary and its why. The structured-error mapping is shared with errorFromCaught, without an unused why callback. The source load doc comment, the contract print throws and the CLI README say a structured source error is reported under its own code. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> registeredGeneratorDescriptors becomes assembleGeneratorRegistrations, with a GeneratorRegistration entry type. The error reference lists the repeated-registration and named-parameter refusals, the spec says builtinGeneratorRegistryMetadata is removed, and deferred.md notes that the assembled generator descriptor list has no production reader. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
There was an error while loading. Please reload this page.
|
Important Review skippedToo many files! This PR contains 383 files, which is 83 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: 11
📒 Files selected for processing: 383
You can disable this status message by setting the
Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
@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: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
size-limit report 📦
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…the older schema header Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…-generator-attributes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # docs/reference/error-reference.md # packages/2-sql/2-authoring/contract-ts/src/composed-authoring-helpers.ts # test/integration/test/planner-golden/manifest.json
…-generator-attributes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # docs/architecture docs/subsystems/10. MongoDB Family.md # packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts # packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.ts
There was an error while loading. Please reload this page.
…act stores the real column type instead of the alias name (prisma#30819) ## At a glance After this PR, a Prisma 8 schema can define a reusable type once and give it generated values: ```prisma types { UpdatedAt = TimestampString(3) @onCreate(now()) @onUpdate(now()) } model Post { id String @id @onCreate(uuid()) createdAt temporal.CreatedAt updatedAt UpdatedAt } ``` - `UpdatedAt` is a type alias, a name for `TimestampString(3)`. Any field typed `UpdatedAt` gets that column type and the current time on create and on every update. - `temporal.CreatedAt` is a type alias that Postgres provides, so users do not have to write their own. Until now, an alias could not carry `@onCreate` or `@onUpdate`. The only way to say "set this timestamp on every update" was a field preset such as `temporal.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: ```prisma types { Slug = VarChar(64) } model Post { slug Slug } ``` The contract used to store the alias, with a column that only pointed at it: ```json "types": { "Slug": { "codecId": "sql/varchar@1", "typeParams": { "length": 64 } } }, "slug": { "codecId": "sql/varchar@1", "typeRef": "Slug" } ``` It now stores the column alone: ```json "slug": { "codecId": "sql/varchar@1", "typeParams": { "length": 64 } } ``` This is the second of three PRs for TML-3607, which carries out ADR 275. The first, prisma#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 `Slug` to `ShortText` changes 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 `@onCreate` and `@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`, `@onCreate` and `@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: - `@id` or `@unique` on an alias, because those describe a model's field, not a type; - a field that repeats an attribute its alias already sets; - an alias defined as another alias. **Ready-made timestamp aliases.** Postgres, SQLite and MongoDB each provide `temporal.CreatedAt` (the time a row is created) and `temporal.UpdatedAt` (the time it is created and every time it is updated). Postgres also has `String` and `JsDate` variants, 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: ```ts const UpdatedAt = field.column(type.TimestampString(3)).onCreate(gen.now()).onUpdate(gen.now()); updatedAt: UpdatedAt, createdAt: field.column(type.temporal.CreatedAt()), ``` `type.*` now has a helper for every type PSL can write, such as `type.VarChar(64)`. The `types` key in `defineContract`, 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/`. - **What the script does:** it rewrites a project's stored contracts and migration snapshots to the new shape and updates their hashes. - **What the user does:** run the script, emit the contract again, then run `prisma db sign`. - **The database itself:** nothing changes, and no migration is needed. 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 - **No database change.** Every saved migration plan and every example migration produces the same SQL as before. Only hashes changed. - **The upgrade script.** Run over this repository, it produced exactly what emitting the contracts again produces. Run over `main`'s demo apps, it produced this branch's migrations. Its tests run Prisma's own migration checker on the result. - **A real upgrade, by hand.** A database was set up with `main` and then upgraded with this branch by following the guide. `prisma db verify` reports no issues. The report is `projects/remove-field-presets/manual-qa-reports/2026-10-21-slice-2.md`. - **Review.** Four rounds of `/drive-code-review`, all findings fixed. All repository checks pass. ## Decisions ADR 275 left open - **Extensions still declare database types in TypeScript.** pgvector and PostGIS declare the types they create in the database (`vector`, `geometry`) through the removed `types` key, and PSL cannot write that. They now use a new key, `databaseTypes`, which means only that. Their contracts do not change. - **A provided alias cannot set a database default.** No pack needs one, and MongoDB has no database defaults. It can be added when a pack needs it. - **MongoDB's aliases use `Date`,** because MongoDB's `DateTime` is deprecated. - **MongoDB's TypeScript builder gets no provided aliases.** It has no `type.*` helpers to build them on. MongoDB TypeScript users write `field.date().onCreate(gen.now()).onUpdate(gen.now())`. This is recorded in `projects/remove-field-presets/deferred.md`. ADR 275 and the ADRs it changes carry dated notes on these points. ## Alternatives considered - **Keep storing aliases in the contract.** Not chosen: the hash would keep changing when a user renames an alias, though the database does not change. - **Split this PR into the schema-language change and the contract change.** Not chosen: an alias that sets a generated value only works once aliases are resolved when the schema is read, so the second PR would depend on the first. - **Keep the TypeScript key named `types` for extensions.** Not chosen: every existing `types` key 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 --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.