Documentation

Docs / Reference

ADR 0059 - Drizzle models and the TypeScript model payload

Status: Accepted (delegated review, 2026-11-10)

Drizzle model schemas (docs/contract/claims/drizzle-models.md, plan the T018 task record (internal) "ORMs in the other first-tier languages"). Written with the change that decides the cached TypeScript model payload (gate, shape, version, validity). Discovery, node shapes, the per-dialect unique form, row and assumption ids and the oracle are fixed by the task file's claim contract and the investigation results; units G2B2-G2B5 implement them and add their implementation notes to this ADR.

Context

Milestone M2 of the project plan asks for ORM models in each first-tier language. Drizzle states tables in TypeScript: pgTable("t", { ... }, (t) => [...]) calls in schema modules that a drizzle-kit config names. The investigation pinned kaneo (drizzle-orm 0.45.4, drizzle-kit 0.31.11) and dokploy (0.45.2, 0.31.9), inventoried every form, checked the semantics in the pinned packages and ran an oracle (drizzle-kit's own SQL applied to a scratch Postgres 17); the claim contract is finalised from it.

Unlike Prisma (ADR 0057), Drizzle cannot be read at link time from retained sources: the schema language is TypeScript, which needs the tree-sitter parse that runs only in the bounded parse workers (ADR 0002, 0006, 0012), and on a cache hit the indexer never parses a file (internal/index/index.go). The existing TypeScript caches do not hold the syntax either: module bindings are RouteExpr values that keep object properties in a map (column order lost), drop array elements and spreads, keep arrow functions as text and read a tagged template's argument as children; urlExpr keeps order and arrays but runs only at URL and config sites.

Options considered

  1. Widen RouteExpr or urlExpr. Every TypeScript file's cache and every route and client consumer would change; rejected for the same reason as ADR 0053 option 1.
  2. Re-parse schema files at link time. A second parse path outside the bounded pipeline, and a parse of every schema file on every warm run (ADR 0030 records a forced reparse on every run as a defect).
  3. A gated, cached, tool-neutral payload (chosen). A new additive field captured during the existing parse only in files that can define Drizzle tables or configure drizzle-kit, holding only module-level declarations and the default export as an ordered reduced tree.

Decision

Consequences

Known gaps

Implementation notes

Discovery and contract table

Tables and columns

Keys, extra config, relations and wiring

Oracle, migrations folder and overlap

Revision after the independent review (2026-11-09)

Class rules, each with a fixture case or test (docs/extract/schema-drizzle.md "Revision after the independent review" has the detail; the contract rows DR-K1, DR-T1, DR-C1, DR-C2, DR-C3, DR-P1 and D are reworded in both tables and the catalogue):

Review notes (delegated review, 2026-11-10)

Report a problem with this pageSource: docs/adr/0059-drizzle-models.md