Documentation

Docs / Reference

Claim contract: Drizzle models

The claim contract of the Drizzle model extractor (ADR 0059) as recorded when it was designed (task T018g2, internal record). docs/extract/schema-drizzle.md and the code table in internal/extract/models/drizzle must equal these rows (TestDrizzleContract).

Claim contract

Finalised from the inventory and the oracle (the investigation). Row kinds: K scope and naming; T tables; C columns and modifiers; X table extra config; E enums; R relations; P provable failures; D the single default branch. Every form the corpora use has exactly one row (counts per row: the T018g2 inventory (internal record)); forms only the fixture uses come from the same oracle runs. The contract test keeps docs/extract/schema-drizzle.md, the Go table and the code 1:1 (plan, shared piece 4). 14 rows: 13 rows plus D; DR-P1 only refuses, DR-P2 and DR-V have no branch.

Dialect rule (developer decision 2026-11-09):

Provider-independent facts (table and column names, column set, nullability, key and index column lists) are claimed for every supported dialect with the dialect's verification.

Rendering rule for sql templates (pinned by the oracle): a template without substitutions is its text verbatim. A substitution is rendered only when it is a column of the same table (${table.col}, ${t.col}): as "<table>"."<column>" in .where(...), check(...) and generatedAlwaysAs(...), and as "<column>" inside an index .on(sql...) expression; any other substitution makes the text unknown. In .default, drizzle-kit refuses substitutions (sqlToStr, bin.cjs:15930-15942 throws): default unknown.

id form claim refusal / unknown assumptions
DR-K1 scope (Discovery above): package dependency, default or --config-named config, literal dialect, schema (path, glob, array), casing, schemaFilter; schema files and the modules their exports reach (export *, export { } from, tsconfig paths) the group (models/drizzle/<config path>), its file set, dialect, pins; marker diagnostics for files outside the schema that call a table builder non-literal dialect/schema, unsupported glob syntax, a config not named by the default or a literal --config, no config: no claims (marker); drizzle-orm 1.x: marker, no claims; one config file run from two package directories that resolve its schema to different files: no claims (schema_model_not_proven, DR-V5), the same files: one group DR-V1, DR-V4, DR-V5
DR-K2 column name omitted (text(), integer({ mode })) the property key; with a literal config casing, the key converted by the pinned rule (drizzle-orm/casing.js:3-13 toSnakeCase/toCamelCase, applied only to omitted names, keyAsName, column-builder.js:8) non-literal casing: name unknown, column claim refused DR-V3
DR-T1 exported module-level const (or a name in an export { } clause) holding pgTable("n", cols, extra?), sqliteTable, mysqlTable, or <s>.table("n", ...) where <s> is an exported pgSchema("s") const a table: name (literal first argument), schema (pgSchema literal; else public on postgresql, none on sqlite/mysql), dialect from the builder module; on postgresql only a table (or enum) whose schema is in the push schema filter: the config's literal schemaFilter, else ["public"] (developer decision 2026-11-10); a table two configs read: claimed once, in the group of the first config by root, when they agree on dialect, casing and schemaFilter (identities are per file) a postgresql table or enum whose schema is outside that filter, or any under a non-literal schemaFilter: not claimed (schema_model_not_claimed; push keeps only the filter's schemas, bin.cjs:16944, generate every schema, bin.cjs:19850); non-exported table: no table (oracle); mysqlSchema(...).table: no table (drizzle-kit skips schema tables on MySQL, bin.cjs:16271); a table two configs read that differ in one of those keys: not claimed in either (schema_model_not_claimed), the other configs of an agreeing set: schema_model_not_claimed naming the group that claims it; non-literal name, pgTableCreator/sqliteTableCreator/mysqlTableCreator (the marker names the tables its calls build), builders in functions or loops, columns not an object literal: D (table not claimed, marker); every such marker ends with the group's list marker, so the group's table_list is may_be_incomplete DR-V2
DR-C1 column builder call from the table's dialect module, from a closed per-dialect list the oracle has run (the investigation: text, varchar({length}), char({length}), integer, smallint, bigint({mode}), serial, smallserial, bigserial, boolean, real, doublePrecision, numeric({precision, scale}), timestamp({precision, withTimezone, mode}), date, time, interval, uuid, inet, json, jsonb on postgresql; text({length, mode, enum}), integer({mode}), real, blob({mode}), numeric on sqlite; the build's fixture adds the rest of the 0.45 list before they are claimed); .array(); spread of a module-level object literal of columns (same file or imported) column name (literal first argument, else DR-K2); SQL type as the oracle catalog shows it (varchar(20) -> character varying(20), timestamp -> timestamp without time zone, .array() -> <type>[]); serial/smallserial/bigserial: integer/smallint/bigint, not null, sequence default; on mysql (mapped) the COLUMN_TYPE MySQL 8.0.19+ reports: serial -> bigint unsigned, boolean -> tinyint(1), char -> char(1), the rest as drizzle-kit writes them; mode, sqlite text({enum}) and bigint({mode}) are TypeScript-only (no fact; no CHECK, oracle) builder outside the run list: type unknown; a non-literal config argument: the facts it carries unknown; spread of anything else: column set not complete; MySQL types from the mapped source only; mysql varchar without a length (MySQL rejects it): type unknown DR-V1
DR-C2 modifiers .notNull(); .primaryKey() (implies not null on every dialect); .unique(name?, {nulls}); .default(x) with x a string, number, boolean, null, array or object literal, an sql template, or a module-level const holding one (same file or imported); .defaultNow(), uuid .defaultRandom(); .references(() => t.col, {onDelete, onUpdate}) with t a table const of the group; .generatedAlwaysAs(sql or () => sql), .generatedAlwaysAsIdentity(opts?), .generatedByDefaultAsIdentity(opts?); client-side $defaultFn, $default, $onUpdate, $onUpdateFn, $type<T>(); MySQL .autoincrement() (integer builders, serial), timestamp().defaultNow() and timestamp().onUpdateNow() nullability; single-column primary key (name not claimed: inline, the database names it); unique: postgresql a UNIQUE constraint <table>_<column>_unique (pre-casing column name) or the literal name, nulls: "not distinct" as nulls_not_distinct: true; sqlite a unique index of that name; default: string 'x' (quotes doubled), number and boolean as written, json/jsonb object or array '<JSON.stringify>'::json(b), array column '{"a","b"}', sql text by the rendering rule, defaultNow() now(), defaultRandom() gen_random_uuid() (bin.cjs:17021-17045); MySQL defaultNow() a default (presence, date.common.js:6-8; MySQL default texts are presence only); foreign key to the referenced table and column, name <table>_<col>_<reftable>_<refcol>_fk (pg-core/foreign-keys.js:55) truncated to 63 bytes on postgresql, actions as written, else no action for both (oracle); generated: generated: "stored" with expression text by the rendering rule; identity: identity: "always"/"by default" and not null; the $-prefixed client modifiers and $type: no fact, and no database default is proven by them a non-literal default or a new Date(...)/call default: default unknown; sql default with a substitution: default unknown; a references target that does not resolve to a table column of the group: foreign key unknown (table partial); identity sequence options other than literals: those facts unknown; .unique() on sqlite under a name used twice: DR-P1; MySQL .autoincrement(): default unknown (AUTO_INCREMENT is not a default), the other facts read; .onUpdateNow() without a default: default unknown (drizzle-orm marks a default, date.common.js:10-14; MySQL's depends on the server), the other facts read DR-V2
DR-C3 customType<...>({ dataType() { return "t"; } }) as a module-level const (same file or imported), used as a column builder column type t as written (kaneo bytea, dokploy text; oracle) dataType with parameters, a non-literal return, or anything else in the object that changes SQL: type unknown; on postgresql a literal other than bytea and text, the ones the oracle compared (Postgres spells others its own way, varchar(255) as character varying(255)): type unknown; on mysql any literal (no literal is mapped): type unknown -
DR-K3 literal casing in the config together with explicit names explicit (literal) column names are never converted (oracle: explicitName kept); index and primary/foreign key generated names use the converted names, unique generated names the pre-casing names - DR-V3
DR-X1 third argument (t) => [ ... ] or the deprecated (t) => ({ ... }) of a table builder, elements: index(name?) / uniqueIndex(name?) with .on(...) or .using(method, ...), column arguments with .asc(), .desc(), .nullsFirst(), .nullsLast(), .op("cls"), .where(sql), .concurrently(); primaryKey({columns, name?}); unique(name?).on(...) with .nullsNotDistinct(); foreignKey({columns, foreignColumns, name?}) with .onDelete()/.onUpdate(); check(name, sql) indexes with name (omitted: <table>_<cols>_index, bin.cjs:16919, cased names), columns, uniqueness, method (btree when absent), per column desc and nulls (default last also for desc(), pg-core/columns/common.js:74-77: .desc() renders DESC NULLS LAST), opclass, partial predicate text by the rendering rule; composite primary key name (omitted: <table>_<cols>_pk, pg-core/primary-keys.js:34; postgresql: its columns not null; sqlite: unnamed, nullability unchanged, A10); unique constraint (postgresql; sqlite unique index) name (omitted: <table>_<cols>_unique); composite foreign keys with actions and name (omitted: <table>_<cols>_<reftable>_<refcols>_fk, truncated to 63 bytes); check name and expression text index .on(sql...): expression index, columns unknown, expression text by the rendering rule; .with({...}) storage parameters: unknown; any other element, a non-array/object body or a block body: D for that element (table partial) DR-V2
DR-E1 exported pgEnum("n", ["a", ...]) or <s>.enum("n", [...]) (exported pgSchema), used as a column builder (same file or imported); MySQL mysqlEnum("col", [...]) and sqlite text({enum}) column forms Postgres enum type (schema-qualified) with its values in order; the column's type is the enum (array with .array()); MySQL enum('a','b') column type (mapped); sqlite text({enum}): text, no fact for the values non-literal values: values unknown; a non-exported enum used by a column: DR-P1 (oracle: no CREATE TYPE, the table fails) -
DR-R1 relations(table, ({ one, many }) => ({ k: one(t, { fields, references }), k2: many(t) })) (0.45) in the group's schema modules ORM-level relations only (developer decision 2026-11-09): per entry, kind (one/many), the source and target table identities and, for one with literal fields/references, the column lists, in table attribute orm_relations; never a foreign_key edge, never a database fact (verification not set; the view labels them ORM relations) target not a table const of the group: target unknown; relations() outside the schema modules (kaneo relations.ts, 31): counted in a marker, not read; defineRelations (1.0): D -
DR-P1 failures provable from the source: a non-exported enum or pgSchema used by an exported table; two exported tables with one schema-qualified name in a group; a column name used twice in one table; two unique constraints with one name in a table (bin.cjs:16997, drizzle-kit exits); a references or extra-config column that is not a column of the named table; on postgresql a foreign key whose referenced columns are neither the primary key nor a unique constraint nor a unique index of a table whose keys are all read (Postgres rejects it; review addition, oracle) diagnostic schema_model_import_failure (row named); no claim for the tables involved a foreign key whose referenced columns are unique only through a unique index (drizzle-kit adds the foreign keys of created tables before their indexes, bin.cjs:29041-29042, so Postgres rejects it from one generate or push): foreign key unknown; other failures: assumed absent DR-V2
DR-P2 drizzle-kit reads only the configured schema: tables defined only in files the scope does not reach none (they are not in the group); covered by DR-K1's marker - DR-V5
DR-V assumptions DR-V1..DR-V6 attached to every record of the group (assumptions) stated, never claimed as facts - -
D anything else: pgView, pgMaterializedView, pgSequence, pgPolicy/RLS (.enableRLS()), pgRole, table creators, tables in functions, unknown builders or modifiers, singlestore/gel dialects, 1.0-only forms (defineRelations, snakeCase.table, casing on builders), a schema module without a model payload (builders imported through a local re-export) nothing; the table or column is partial with D as reason, or a marker diagnostic schema_model_unread (tool drizzle) for whole declarations (one per module without a payload, naming its exported values) always -

Rows DR-P2 and DR-V exist so the inventory can count every scope form and the contract test can name the assumption row; neither has a claim branch. The claim side rows are DR-K1, K2, K3, T1, C1, C2, C3, X1, E1, R1 (ten).

Report a problem with this pageSource: docs/contract/claims/drizzle-models.md