Repository navigation
TML-3389: Generator arguments and discriminator values are typed values, and a generator must fit its column - #30792
Merged
Merged
Conversation
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nostics Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… in @internal/ids Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nts are integer values
The SQL family declares autoincrement, now, ulid, uuid, cuid and nanoid once,
in sqlDefaultFunctionSignatures({ integer }); Postgres passes pg/int4 and SQLite
sqlite/integer, and the adapters keep only lowering. Each argument of uuid, cuid
and nanoid is read like a default of the integer type, then checked by its
function, reporting PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT at the argument.
Arity messages name the callee as a default function.
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]>
… fixed or built from the data types An extension that registers a default function with a plain signature keeps working; only signatures whose arguments are values of a data type are built from the stack's data types. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…_INVALID_DEFAULT_FUNCTION_ARGUMENT 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]>
…checks a parsed value The SQL family's integer arguments now refine a dataTypeValue instead of copying its fields into a new argument type. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d nanoid from the data types Its invalid-argument test expects the shipped messages and code, and a new test registers one signature as an object and one built from the data types. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…porary folders Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…efault function's call The @default arms use it, and it is exported so another contract source binds a default function's arguments the same way. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…checked through the signatures The Prisma 7 reader binds uuid, cuid and nanoid arguments as Prisma 8 PSL does, so uuid(5) and nanoid(1) are refused with the function's message at the argument under PSL.PRISMA7_UNKNOWN_DEFAULT instead of lowering to something else. FUNCTION_ARGUMENT_KEYS is gone; Prisma 7's cuid() still means cuid(2). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…und 1 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]>
applicableCodecIds becomes applicableDataTypes, passed by each target: text generators apply to pg/text, pg/char and pg/varchar on Postgres and to sqlite/text, sqlite/character and sqlite/character-varying on SQLite, and the UUID generators add pg/uuid. The check compares the column's data type, so String @default(uuid()) now emits on SQLite. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…String column 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]>
…nsions 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]>
…descriptor is an internal error 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]>
…iminator column's type A @@base value is read, cast into the discriminator column's data type and checked by its codec, like a default, and the duplicate check compares the stored values. A discriminator column may be any text type (String, Char, VarChar), so a number is refused at the value and a VarChar(5) column refuses a longer value. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… through the ORM on PGlite and SQLite Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…item is done 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]>
…und 1 Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…named text types Each SQL target names its text data types (text, character, character varying), declares them as authoring textDataTypes and passes the same list to its generator descriptors. A discriminator column is accepted only when its data type is one of them, so Uuid, Inet and Bit columns are refused as before. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…h refusals Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d sits above it again 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]>
GeneratorFunctionField.length is a required key typed number | undefined. The PSL reader, the TypeScript builder, the Prisma 7 reader (now() for @updatedat included) and contract print pass the column's length in its normal form, through sqlCodecColumnLength in sql-contract; Mongo passes undefined. contract print now refuses a generator its read-back would refuse, such as uuid() on a Char(5) column. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…es, and the extension notes say so Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ator call it would write is refused Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e discriminator note names Postgres and SQLite columns Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
@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 20, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 20, 2026
…ped-written-values Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
wmadden
enabled auto-merge
October 20, 2026 16:18
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 20, 2026
…n's fix hint Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden
enabled auto-merge
October 20, 2026 17:01
…ped-written-values Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # docs/architecture docs/adrs/ADR 254 - Data types and casts.md
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-prisma__orm
that referenced
this pull request
Oct 21, 2026
…cisions, file its deferred work, delete its folder (prisma#30811) ``` $ ls projects/data-types-completion ls: projects/data-types-completion: No such file or directory ``` ## The decision The "Data types own column types" project (Linear P-TML-1145) is finished. All of its slices have merged, the last as prisma#30792. This pull request deletes its working folder, `projects/data-types-completion/`, after checking that nothing in it is lost. ## What was checked before deleting **Every decision has a permanent home.** I mapped all 133 decisions recorded in the project's design notes, design, spec and slice plans to where they are recorded outside the folder: | Where the decision stands | Count | | --- | --- | | Recorded in an ADR, a reference doc, a README or a released upgrade instruction | 104 | | Superseded by a later decision of the project or by ADR 275 | 8 | | About the project's ordering and process only | 18 | | True but recorded nowhere, now added here | 3 | Most decisions live in ADR 254 "Data types and casts". The three that were missing, now added: - ADR 254 "Alternatives considered": why `contract.json` does not keep `nativeType` as a derived copy, and why databases are re-signed with `db sign` instead of a map from old hashes to new ones or a one-time rewrite command. - The CLI README's `db sign` steps: on MongoDB each space's marker is written on its own, with no transaction around them. **Stale references fixed.** A code comment in the Postgres Prisma 7 type map cited the design document by section number. The codec authoring guide said the Prisma 7 reader "will" use the inferred constructor, which it already does. The error reference still documented `CONTRACT.DATA_TYPE_ENTRY_KEY_INVALID`, which the project deleted. ADR 204 named `validateContract`, which is now `contractFromJson`. **Deferred work is in Linear.** The 27 items in `deferred.md`: - 16 still open, now filed: TML-3658 to TML-3673. - 3 open and already ticketed: TML-3598 (stale Supabase `contract.prisma`), TML-3500 (enum CHECK literals), TML-3470 and TML-3647 (Mongo validator enums). - 6 fixed by the project's own slices or by prisma#30790. - 2 dropped: the Postgres DDL walker reads type text on purpose, because a hand-written migration column may have no codec; and a number in a SQLite `DateTime` column is read as milliseconds by design, and Prisma never writes another form. **TML-3283** (bytea and vector defaults failing the schema check) was already Done. I added a comment saying how `main` handles it now: through the column's codec, as ADR 254 describes. **Retrospective.** The final retro is in `drive/retro/README.md`. Its main lesson: before building a slice, look at open and recently merged work in the same subsystem. A redesign of client generators merged on `main` while the last slice was being built, and the slice had to be ported onto it after review. ## Alternatives considered - **Keep the folder as a historical record.** Git history keeps it, and a folder that describes finished work as current misleads the next reader. Agent: frigg-97 🤖 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 contract validation, data-type migration, and database-signing guidance in architecture decision records. * Updated Prisma 7 parameterized type-constructor guidance. * Documented MongoDB’s independent contract-space signing and PostgreSQL/SQLite all-or-nothing signing behavior. * Added recurring guidance on concurrent work, testing, validation, reviews, and database quality checks. * Removed the obsolete invalid data-type entry-key error reference. * Simplified terminology in PostgreSQL type-mapping documentation. <!-- 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]>
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.
nanoid(8.5)Expected an integer literal(PSL_INVALID_ATTRIBUTE_SYNTAX)Expected a number that pg/int4 can hold; got pg/numeric(PSL_VALUE_TYPE_INCOMPATIBLE), at the argumentuuid(5)Expected one of: 4 | 7(PSL_INVALID_ATTRIBUTE_SYNTAX)uuid: version must be 4 or 7, got 5(PSL_INVALID_GENERATOR_ARGUMENT), at the argumentuuid(5)in a Prisma 7 schemauuid()on aVarChar(5)columnuuid() writes 36 characters, which does not fit a column of 5 characters.uuid(uuid((4 | 7)?)The decision
The arguments of the client generators
uuid,cuidandnanoidare values of the target's integer type, read by the same rule as a column default, then checked by the generator itself. A generator is refused on a column too short for what it writes. A polymorphic model's discriminator value is a value of the discriminator column's text type. This is the last part of the "Data types own column types" project (Linear TML-3389).How it works
What the rule is. Since ADR 254, a value written in a schema has a data type, and a position takes it only if the position's type is that type or declares a cast from it. Defaults follow that rule. Generator arguments did not:
nanoid(8)'s8was checked by a hand-written "integer between 2 and 255" shape, so the errors were generic and the limits were written in five places.Generator arguments are typed values.
uuid(version?),cuid(version)andnanoid(size?)now take one value of the target's integer type (pg/int4on Postgres,sqlite/integeron SQLite), read and cast like a default, and then the generator checks its own limit:uuid4 or 7,cuid2,nanoid2 to 255. A decimal such as8.5or4.0is not an integer value, so it reports the missing cast. The limits are written once, in@internal/ids. Hover and signature help keep showing the allowed values,uuid((4 | 7)?).The Prisma 7 reader uses the same signatures. It used to accept any argument and lower
uuid(5)to version 4 and passnanoid(1)through. It now refuses those, and named arguments, with the same messages.Generators fit their column. Each generator states how many characters it writes (
uuid36,ulid26,cuid24,ksuid27,nanoidits size), and a column whose length is shorter refuses it. The length is read in the column type's normal form, so a bareCharcounts as one character. SQLite is never refused, because SQLite does not limit a text column's length.contract printuses the same check, and says why when it refuses.Discriminator values are values of the column's type.
@@base(Shape, "circle")now reads"circle"into the discriminator column's type, so aVarChar(5)discriminator refuses it as too long, and duplicates are compared by stored value. A discriminator column may be any of the target's text types:String,Char(n)orVarChar(n)on Postgres,Stringorsql.String(n)on SQLite. Each target names its text types once (textDataTypes), and an extension may add its own. The ORM already read and wrote the discriminator through the column's codec, which aChar(n)column's padding needs; a round trip is now tested.Built on ADR 275. While this was being built,
mainmoved client generators to@onCreateand@onUpdate, bound to codecs (ADR 275). This pull request follows that design: which columns a generator applies to is still decided by its codec binding, and the length check lives in those bindings.What users and extension authors see
Upgrade notes are in
upgrade-instructions/pending/generator-function-arguments-and-column-length/.uuid(5)used to make version 4 UUIDs, so writeuuid(4)to keep them); generators refused on a column too short for them; the discriminator message now says "must be text".uuid,cuidandnanoidwith its integer type throughsqlIntegerArgumentGeneratorFunctions; a generator signature may be a function of the stack's data types;GeneratorFunctionField.lengthis required;buildContractDefinitionrequires the codec and data type lookups; the newtextDataTypescontribution.No committed contract, migration or snapshot changes, and no DDL changes.
How it was checked
String,Char(6)andVarChar(10): create, polymorphic read andvariant()through the ORM on PGlite and SQLite.projects/data-types-completion/slices/5/build-review.md.projects/data-types-completion/slices/5/manual-qa.md): the above end to end against PostgreSQL 17 and SQLite, the language server's hover over stdio, andcontract printreading back to identical hashes.Not in this pull request
variant()takes that text; changing either is a new feature.projects/data-types-completion/deferred.md: Mongo still checks its discriminator by the type nameString; an optional discriminator field is accepted.Alternatives considered
variant(); it is not needed to type the values that exist today.Agent: frigg-97
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
autoincrement()andnow()default functions.Bug Fixes
Documentation