Repository navigation
TML-3386: SQL data types declare their names, parameters and texts once - #30547
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…m the contract Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d contracts Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ript Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ssion settles Co-Authored-By: Claude Fable 5.1 <[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]>
…and infer failure 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]>
… project Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ite data types Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…their decisions Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… contract A new integration test plans every committed Postgres and SQLite contract from an empty database and compares the planner operations with a golden file. The goldens are recorded from the planner as it is before any data type changes. A contract in a format the validator refuses today is recorded as unreadable so the set left out is committed and reviewed with the rest. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
`DataType` and `DataTypeSpec` gain an optional `params`, an arktype object schema of the type parameters, and `dataType()` carries it through. A type without `params` has none. The SQL data type module builds on it to validate and render type parameters. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d normal form New entry point `@internal/sql-contract/data-type`. `sqlDataType` declares a SQL data type with the texts a migration writes and the catalog prints, a parameter schema, a normal form, and either texts or a kind claim with `render` and `fromReported`; it refuses a declaration that breaks a rule. `renderSqlTypeName` writes the name for raw parameters, `renderSqlCatalogText` prints the catalog text for the normal form, `sqlBaseName` gives the name with no parameters, `dataTypeParams` keeps the keys the type declares, and `resolveReportedSqlType` recognises a reported type from every claiming text or kind claim in a list of data types. Parameters that fail the schema, or a parameter set no text takes, raise the structured error `CONTRACT.TYPE_PARAMS_INVALID`, added to the error reference. The public packages that mirror the sql-contract entry points gain the matching export. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…tch a Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…sembly order DataTypeLookup gains all(), which returns every assembled type in the order the stack assembled them: contributor by contributor, each in its own order. The resolver of reported SQL types and the assembly check for colliding claims need the whole list, which get and has cannot give. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ext rules A kind claim is now checked like a text claim: resolveReportedSqlType validates the parameters fromReported reads against the type's schema, returns nothing when they fail, and returns their normal form. sqlBaseName validates the parameters it passes to render, so an enum with no typeName fails with CONTRACT.TYPE_PARAMS_INVALID instead of a TypeError. A declared text may no longer contain a double quote, and a display must write every placeholder exactly as its text does. Text preparation removes a space after an opening bracket or a comma when a double quote follows it, as it does before any other character. The error reference names the catalog case and sqlBaseName. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The planner golden test selected contracts by file name, so it missed 40 committed SQL contracts, among them the 35 Prisma 7 reader fixtures named expected-contract.json. It now reads every tracked JSON file and keeps those whose top level names the SQL family and the Postgres or SQLite target. An extension pack that lives inside an example and cannot be imported here is listed in the golden under extensionsNotLoaded instead of under extensions. Any other pack the test does not know fails the test. A contract the planner refuses with a structured error is recorded with that error, as a contract the validator refuses already is. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…now finds Recorded from the planner as it is on this branch, which no dispatch has changed yet: 40 new goldens for the contracts the file-name selection missed, and nine existing goldens that now list their example-local packs under extensionsNotLoaded. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…n type shape No committed contract held a numeric column with a precision and no scale, a char, bit or varchar column with no length, several SQLite codecs, or a typeRef alias of a type written with no parameters. These are the shapes where writing a column type from its data type can go wrong, so the planner golden test could not see such a change. Two TypeScript contracts under test/planner-golden/fixtures fill the gap: one for Postgres with pgvector and postgis, one for SQLite. Each has one column per codec in every parameter shape a contract can hold today, list columns on Postgres, and typeRef aliases. They are emitted by emit-fixture-configs like the other generated fixtures, so fixtures:check holds them fixed. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Recorded from the planner as it is on this branch, which no dispatch has changed yet. The Postgres golden shows the typeRef columns of uuid and of char with no length written as quoted names, which is the one DDL change this project makes. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A codec-instance entry in types needs typeParams, so the uuid and char aliases carry an empty object; the emitted contract is unchanged. A type-only import of postgis geojson lets the declaration of the exported contract name the geometry value type. 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]>
…arameters and normal form Each pg/* data type is now a SQL data type: the texts a migration writes and the catalog reports, the texts that only claim a reported type, its parameter schema with the bounds PostgreSQL enforces, and its normal form. pg/enum claims the enum kind, renders its type name quoted at the first dot, and reads a reported enum as its name, qualified outside public. Every Postgres codec now uses its data type's parameter schema, so a bound is written once. The bounds change where the old schemas differed: char and varchar lengths stop at 10485760, bit and varbit lengths at 83886080, a numeric scale stops at 1000 and needs a precision, and an enum type name must not be empty. pg/unboundedint@1 now takes the numeric parameters too. postgresCodec takes the data type instead of its id and gives the adapted codec the data type's schema, not the template's. 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 from pg.enum's PSL path reads only typeParams from columnFromEntity; the type name comes from the pg/enum data type. The Mongo collection validator reads BSON types from the data type a codec represents. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ixes round 4 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]>
…iveJsonSchema deriveJsonSchema and derivePolymorphicJsonSchema take a required MongoTypeLookups after their fields, and the optional codecLookup argument moves into it. The entry mongo-derive-json-schema-takes-lookups says so, with a call before and after. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…n's rule numbers The scenario A comment slice 1 rewrote also loses its project ids. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… the codec lookup buildSqlContractFromDefinition already requires both lookups, so the branches that skipped encoding a default or checking enum members without a codec lookup were dead. columnCodec, codecForDefault, encodeColumnDefault, encodeEnumMembers and checkMemberValues now require it, and a column default is always encoded through a codec. 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]>
Main brought TML-3409 and TML-3443. The SQLite schema diff keeps slice 1's imports, which no longer need ifDefined, and adds main's SQLITE_NOW_EXPRESSION. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… every data type in its table Design 13.8 states the rule for the whole Prisma 7 table and says where an exception would be listed. The slice 3 outline names the Prisma 7 reader, and deferred.md records rewording the inferred mark's documentation so it names no single reader. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e-text tables pgIsTextLikeNativeType and SERIAL_FAMILY_TYPES read type text a migration author may write by hand, and no design section replaces them. They leave the slice 3 grep row, and deferred.md records why the walker cannot read a data type for every column. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…kups Main's new now() plan-diff tests pass the SQLite test components, so the planner can find the column's codec, and its new marker-read tests build the Postgres control adapter with the data type lookup it now requires. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Each inventory header says it was made on 2026-09-29 for planning pull request #30518 and that its raw outputs were not kept, without the local paths or the commit not on main. The slice plan says the review artefacts are local. Design 3.1 names the PSL-only constructor sets and the targets' own sets, and 3.2 names the runtime adapter's create(stack). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…n outside assembly "Assembly is strict" becomes "Checks on the assembled stack", because items 8 to 10 run when the SQL family creates its control instance. The one link to the heading follows. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d the constructor-set nouns Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…default
TML-3409 makes a SQLite now() default store strftime('%Y-%m-%dT%H:%M:%fZ','now'), so examples/prisma-8-demo-sqlite plans differently. Its new recording on this branch is byte-identical to main's planner output, recorded in a separate checkout of main as before. The only differences from main's planner remain the typeRef quoting fix and the unregistered-codec error code.
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…h the target The Temporal guard and the precision-bound tests check only target facts, so they move from the Postgres adapter to the target and import from ../src/core. The adapter's authoring-contribution tests move to its descriptor-meta test, as SQLite has them. Six hand-built unions in the target's tests become postgresPslTypeConstructors. The 556 test titles of the affected files are the same before and after. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…xes round 5 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]>
5 tasks done
wmadden-electric
enabled auto-merge
October 6, 2026 08:11
This was referenced Oct 6, 2026
wmadden
pushed a commit
that referenced
this pull request
Oct 6, 2026
…e contract (#30617) On `main`, the planner golden test fails: ```text FAIL test/planner-golden/planner-ddl-golden.test.ts > records exactly the committed contracts in the manifest - "packages/3-extensions/sql-orm-client/test/fixtures/polymorphism/generated/contract.json", ``` This pull request adds that contract's entry to `test/integration/test/planner-golden/manifest.json`, recorded with `main`'s planner. With it, the golden test passes on `main` (696 tests). The golden test came with TML-3386 (#30547). It requires one manifest entry for every committed SQL contract. TML-3403 (#30560) committed this contract after that. Its merge queue run skipped the integration tests, so the missing entry was not caught. Refs: TML-3386 Agent: minerva-41 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Expanded regression coverage for generated polymorphism contract output, helping verify that planner results remain consistent. <!-- end of auto-generated comment: release notes by coderabbit.ai --> 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.
Slice 1 of the project "Data types own column types" (Linear TML-3386). It also carries the project documents that planning PR #30518 proposed, which is closed in favour of this one.
At a glance
A Postgres data type now declares, in one place, how the database writes it, how the catalog reports it, which parameters it takes, and their normal form:
A type constructor names the codec and maps its arguments onto the data type's parameters. It carries no type name and no bounds of its own:
Everything that used to compute or copy a column's type name now reads the declaration: the contract writers, both migration planners, the
ALTER COLUMN TYPEpostcheck, the Postgres parameter casts, and the Prisma 7 reader.The decision
Every fact about a SQL database type is declared once, on the data type, by the package that owns it (a target such as Postgres, or an extension such as pgvector). Every copy of those facts is deleted.
contract.jsondoes not change in this slice: the column still storesnativeType, but that string is now written from the declaration, and a test proves the DDL of every committed contract is byte-identical.Before this change the name of a column's database type was written or computed in eight places that disagreed: codec
targetTypes, thenativeType()codec hook, theexpandNativeTypecontrol hooks, a type metadata registry, the adapters'normalizeNativeType, the constructor templates'nativeType, hand-written descriptors, and the Prisma 7 binding. Adding a type meant editing several tables, extension types were invisible tocontract infer, anddb verifycompared strings.What the declaration holds
written(a migration writes it),catalog(the database reports it), both, or neither (it only recognises a reported type).numeric(10)is written asnumeric(10)but reported asnumeric(10,0), sopg/numericdeclares both texts. Placeholders such as{precision}name a parameter; only integers may be substituted.paramsis an arktype object schema and is the only place a bound is written.pg/numericallows a negative scale, as Postgres 15 does. A codec'sparamsSchemais its data type'sparams, referenced, never restated. Constructor and preset arguments lost theirminimumandmaximum; PSL reports a violation at the argument withPSL_INVALID_ATTRIBUTE_ARGUMENT, and a TypeScript contract refuses it when it is built withCONTRACT.TYPE_PARAMS_INVALID.normalizegives the parameters the catalog compares by:numeric(10)becomes{ precision: 10, scale: 0 };charbecomes{ length: 1 }. Writing uses the raw parameters, so migration SQL is unchanged.pg/enumdeclaresclaimsKind: 'enum'and arenderhook that quotes the type name, instead of texts.The Postgres target declares every Postgres type, pgvector declares
vector({length}), postgis declaresgeometryandgeometry(Geometry,{srid}). SQLite declarestext,integer,real,bloband two new types,characterandcharacter varying, which thesql/char@1andsql/varchar@1codecs now name on SQLite. Mongo data types declare the BSON types they are stored as withmongoDataType.Who declares and who reads
type.*helpers (BigIntNumber,UnboundedInt,pg.enum). It defines its PSL-only constructors (postgresPslTypeConstructors,sqlitePslTypeConstructors), and its adapter contributes those, so the TypeScript builder'stype.*helpers do not change.renderSqlTypeName.SERIAL, identity values, JSON defaults and the safe-widening table are keyed by data type id. The Postgres SQL renderer casts a parameter to the type's base name:$1::integerbecomes$1::int4, and avarchar(255)column casts ascharacter varyingwith no length, because an explicit cast with a length would truncate.inferred; when two data types' claiming texts would both match one reported type; and when a codec represents a data type that is not a SQL column type. The last two checks run when the SQL family is created, so CLI commands report them and the language server does not. The SQL family's own data type,sql/expression, is the type of a written SQL expression and no column has it.targetTypes,targetTypesFor,byTargetType, thenativeType()hook andnativeTypeFor, everyexpandNativeTypehook,buildNativeTypeExpander,typeMetadataRegistry,normalizeNativeType,validateScalarTypeCodecIds,assertSafeNativeTypeandCONTRACT.NATIVE_TYPE_INVALID. ADR 171 is superseded by ADR 254.Behaviour changes to know about
types {}alias are written like any column of the aliased type. Atypes { Id = Uuid }alias used to write"uuid", quoted, which Postgres rejects. Now it writesuuid. No committed migration contains such a column.ALTER COLUMN TYPEcompares the database's reported type with the name Postgres prints for the new type. For an enum that means"UserRole"quoted anduser_rolenot, whether or not the column goes through an alias. Before, a mixed-case enum name reached through an alias failed this check. Slice 3 replaces the text comparison with a type identity check.Numeric(10)column is compared asnumeric(10,0), which is what Postgres reports, so it now applies and verifies clean.'{}'instead of'', which Postgres refused for an array.invariantscolumn bindspg/text@1as a list instead ofpg/text-array@1, which is never written. DDL and stored rows are identical, so a signed database still verifies.defineContractbuilds the lookups from the target and the listed extensions.contract inferand the PSL printer write a namespaced constructor with no arguments with parentheses,postgis.Geometry(), because the reader treats a dotted name without them as a scalar type.sridis optional now, so this case can occur. Names without a namespace are unchanged.PSL_DEPRECATED_SCALAR_NAME) and the earlier-name hint for an unresolved type used to sayuse "X" (stored as BSON string). They now sayuse "X".CONTRACT.TYPE_PARAMS_INVALID; no column helper checks on its own. PSL reports the same violation at the argument, and thetype.*helpers keepCONTRACT.ARGUMENT_INVALID.Upgrading
Two entries under
upgrade-instructions/pending/data-types-declare-names/, both validated by execution against the base commit:extension/instructions.md: replacedataType(id)withsqlDataTypeormongoDataTypedeclarations; deletetargetTypesand the rendering hooks; point the codec'sparamsSchemaat the data type; dropnativeTypeand bounds from constructor templates; passdataTypesfrom runtime descriptors; expect$1::int4in logged SQL.app/instructions.md: list the extensions a TypeScript contract uses; re-emit SQLite contracts, whosecontract.d.tsgains aggregate rows for the two character codecs; column parameter errors are nowCONTRACT.TYPE_PARAMS_INVALIDand are raised when the contract is built.Proof
main's planner. It commits one SHA-256 per contract intest/integration/test/planner-golden/manifest.json, hashed from recordings made withmain's planner; only the two fixture contracts keep their full planner output for review. Of 344 contracts, 341 plan identically; two differ only by thetypeRefquoting fix and one only by the planner's error code for an unregistered codec.normalizeapplied twice equals once.pnpm fixtures:checkshows no contract change. The framework vocabulary count fell from 272 to 262.What later slices do
Slice 2 (TML-3388) makes
contract.jsonstoredataTypeinstead ofnativeTypeand ships the upgrade script. Slice 3 (TML-3387) wiresresolveReportedSqlType, which this slice defines and unit-tests, into introspection, verify and infer. Slice 4 (TML-3389) types written values outside defaults.Alternatives considered
nativeTypestrings and normalise them on read. Rejected in the design: it keeps eight sources and cannot recognise an extension's type.sql/char@1andsql/varchar@1. Rejected: a second source for which codecs a target has. The cost accepted instead is two aggregate rows in each SQLitecontract.d.ts.numeric(10,0)forNumeric(10)). Rejected: it would change migration SQL for existing columns.Project files:
projects/data-types-completion/(spec, design, plan, decision record, slice plan and in-loop review log).Agent: thranduil-81, minerva-41