You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
Repository navigation
TML-1662: Store column native type in contract - #30
Currently we store the column type as the codec identifier. We need to be able to verify
the database schema using only the contract data stored in the database, so without knowing
the column-codec mapping we can't do that.
This makes it much simpler: the contract columns will store nativeType and codecId.
Codec information will be ignored by the migration system and the database when comparing
contract to schema. Application query DSLs can ignore the native type and use the codec ID
exclusively.
Summary of changes to implement the “native + codec types” brief
SQL contract column shape and validation
Updated StorageColumn in @prisma-next/sql-contract to require nativeType: string + codecId: string + nullable: boolean for all SQL columns.
Adjusted Arktype validators in both sql-contract and sql-contract-ts so contracts and storage structures are only valid when both nativeType and codecId are present.
Updated the SQL contract README and factories (col, table, storage, contract) and tests to use the new { nativeType, codecId, nullable } shape everywhere.
Contract authoring and example contracts
Refactored the SQL TS contract builder (@prisma-next/sql-contract-ts/contract-builder) so .build():
Reads codecId from the column builder state.
Requires a nativeType on each column (set when the column is defined), and throws if it is missing.
Emits storage.tables.*.columns.* as { nativeType, codecId, nullable }.
Updated the demo app contract (examples/prisma-next-demo/prisma/contract.ts) to use column-type descriptors like int4Column, textColumn, timestamptzColumn, and vectorColumn, which carry both nativeType and codecId into the builder.
Schema IR and verification
Clarified SqlColumnIR in @prisma-next/sql-schema-ir as:
Ensured the Postgres control adapter sets SqlColumnIR.nativeType for introspected columns based on information_schema (handling varchar, numeric, etc.).
Updated SQL family schemaVerify to:
Compare contractColumn.nativeType to schemaColumn.nativeType ?? schemaColumn.typeId for type compatibility.
Keep nullability checks separate.
Use the SQL type metadata registry to warn when codecId’s registry nativeType disagrees with the contract’s nativeType, without blocking structural validation.
Migration planner (planMigration)
Updated the SQL migration planner in @prisma-next/sql-migrations so columnTypeCompatible:
Compares contract.nativeType to schema.nativeType (no longer mixing codec IDs with native types).
Applies the same nullability rules as db init requires (no narrowing; widening allowed).
Left the rest of the planner logic intact: it still plans additive operations (create table, add column/PK/UK/FK/index, extension ops), tolerates schema supersets, fills in subsets, and fails on real conflicts.
Lanes, runtime, and emitter
Updated SQL lane, ORM lane, and relational-core logic to treat codecId as the only type ID for codecs and type inference (replacing usages of StorageColumn.type).
Adjusted SQL runtime codec validation to collect and check codecIds from columns.
Tightened the SQL contract emitter so it:
Validates that every column has nativeType: string and codecId: string.
Emits contract.d.ts with the enriched column type { nativeType, codecId, nullable }, making the generated contract type reflect both DB structure and codec configuration.
Summary by CodeRabbit
New Features
Public column-type descriptors added (including vector) for reuse.
Improvements
Contracts now represent columns with nativeType + codecId; validation, emit, tooling and runtime flows updated.
Query/plan metadata and parameter descriptors expose codecId and nativeType instead of the prior type field.
Better separation of schema vs logical validation; reduced redundant re-validation.
Tests
Tests updated to new column shape; added per-test temp-dir helpers and disk-based contract emit/load utilities.
Chores
Added package exports and build entries for column-type and test descriptor modules.
✏️ Tip: You can customize this high-level summary in your review settings.
Currently we store the column
typeas the codec identifier. We need to be able to verifythe database schema using only the contract data stored in the database, so without knowing
the column-codec mapping we can't do that.
This makes it much simpler: the contract columns will store
nativeTypeandcodecId.Codec information will be ignored by the migration system and the database when comparing
contract to schema. Application query DSLs can ignore the native type and use the codec ID
exclusively.
Summary of changes to implement the “native + codec types” brief
SQL contract column shape and validation
StorageColumnin@prisma-next/sql-contractto requirenativeType: string+codecId: string+nullable: booleanfor all SQL columns.sql-contractandsql-contract-tsso contracts and storage structures are only valid when bothnativeTypeandcodecIdare present.col,table,storage,contract) and tests to use the new{ nativeType, codecId, nullable }shape everywhere.Contract authoring and example contracts
@prisma-next/sql-contract-ts/contract-builder) so.build():codecIdfrom the column builder state.nativeTypeon each column (set when the column is defined), and throws if it is missing.storage.tables.*.columns.*as{ nativeType, codecId, nullable }.examples/prisma-next-demo/prisma/contract.ts) to use column-type descriptors likeint4Column,textColumn,timestamptzColumn, andvectorColumn, which carry bothnativeTypeandcodecIdinto the builder.Schema IR and verification
SqlColumnIRin@prisma-next/sql-schema-iras:typeId= codec ID,nativeType?= DB-specific type.SqlColumnIR.nativeTypefor introspected columns based oninformation_schema(handling varchar, numeric, etc.).schemaVerifyto:contractColumn.nativeTypetoschemaColumn.nativeType ?? schemaColumn.typeIdfor type compatibility.codecId’s registrynativeTypedisagrees with the contract’snativeType, without blocking structural validation.Migration planner (planMigration)
@prisma-next/sql-migrationssocolumnTypeCompatible:db initrequires (no narrowing; widening allowed).Lanes, runtime, and emitter
codecIdas the only type ID for codecs and type inference (replacing usages ofStorageColumn.type).codecIds from columns.nativeType: stringandcodecId: string.contract.d.tswith the enriched column type{ nativeType, codecId, nullable }, making the generated contract type reflect both DB structure and codec configuration.Summary by CodeRabbit
New Features
Improvements
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.