Documentation

Docs / Reference

ADR 0057 - Prisma models

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

Prisma model schemas (docs/contract/claims/prisma-models.md, plan the T018 task record (internal) "ORMs in the other first-tier languages"): file type and discovery, the hand-written lexer and parser, node shapes and the unique-index decision, row and assumption ids, the oracle, and the model kit's extension for Prisma's keys (T018g0 review). Written with step G1B1; step G1B0, which ran first, recorded the store read that keeps /api/v0/schema/sets fast for the larger model schemas Prisma brings (last section; developer decision 2026-11-09: the note goes into this ADR because ADR 0058 was accepted before G1B0 finished).

Context

Milestone M2 of the project plan asks for ORM models in each first-tier language, Prisma first for TypeScript, each with a pinned corpus and its own claim contract. Prisma states a whole database schema in .prisma files: the tables Prisma Migrate creates follow from the file, the pinned Prisma version and the datasource's provider. Two corpora are pinned (umami 7.10.0, hoppscotch 7.9.1; plan decision G4). The investigation inventoried every form they use, checked the semantics in the pinned Prisma sources and ran an oracle (Prisma's own SQL applied to a scratch Postgres 17, then the catalog); the claim contract (26 rows) is finalised from it. The shared model kit (ADR 0058) emits the records; its review (C4) left composite foreign keys, on_update, constraint names and a stated primary-key order to Prisma.

Options considered

  1. Reading the schema. (a) A tree-sitter grammar for the Prisma schema language (a community grammar exists): a new grammar in the parser pool, a cached payload, and a grammar that is not Prisma's own, so its accepted language differs from Prisma's in places nobody checked. (b) Prisma's own parser (the Rust psl crate or its WebAssembly build from @prisma/prisma-schema-wasm): exact, but a new runtime dependency (a Wasm module of several MB per version, or cgo). (c) A hand-written lexer and parser in Go that follows Prisma's grammar file (datamodel.pest) rule by rule, at link time over retained sources, as T018a reads SQL.
  2. Finding the schema. (a) Every .prisma file is a schema. (b) The CLI's rule: the package that depends on Prisma, its config file's literal schema, else ./schema.prisma then ./prisma/schema.prisma.
  3. Unique attributes. (a) @unique/@@unique as unique constraints (as an ORM's docs describe them). (b) As unique indexes, as Prisma Migrate creates them (CREATE UNIQUE INDEX; no u constraint in any oracle run).
  4. Kit extension for Prisma's keys. (a) A Prisma-only foreign-key record beside the kit's. (b) Optional fields on the kit's ForeignKey and Table that only Prisma sets, written only when set, so SQLModel's records stay byte-identical.

Decision

Consequences

Known gaps

Relations, failures, versions and wiring

Decisions

Prisma 5 and 6 (developer decision 2026-11-09)

Discovery accepts proven majors 5, 6 and 7. Each gate below is taken from Prisma's own source at the version where the behaviour changes (prisma 5.22.0 and 6.19.3, their history between 6.0.0 and 6.19.3, and the prisma-engines commits 605197351a3c (5.22.0) and c2990dca591c (6.19.3)):

behaviour gate
config file none before 6.4.0; prisma.config.ts 6.4.0 to 6.12.x (early-access rules not modelled: not proven); from 6.13.0 the c12 names of 7.9.1, literal schema first
package.json "prisma": {"schema"} read by 5 and 6 (after a config schema); a folder needs prismaSchemaFolder before 6.7.0 (not proven)
default lookup schema.prisma, prisma/schema.prisma; before 6.6.0 a prisma/schema folder may be the schema or conflict (not proven)
@@schema multiSchema preview feature before 6.13.0 (GA in 6.13.0); without it schemas is PR-P1 and @@schema unknown
join table key primary key on postgresql from 6.0.0; Prisma 5 a unique index (unknown)
client defaults cuid(2), uuid(n) from 6.0.0, ulid() from 6.2.0; earlier: default unknown
mysql, sqlserver, cockroachdb mapping cited for 7 only; provider-dependent facts unknown on 5 and 6

Without an exact locked version, a Prisma 6 minor is not proven: a gate that depends on it takes the outcome every 6.x release agrees on, or leaves the fact (or the schema) unknown. Postgres types, defaults, keys, indexes and foreign keys render the same at 5.22.0, 6.19.3 and 7.10.0 (renderer and sql_schema_calculator.rs compared), so they are claimed with verification: "oracle"; step G1B4 runs the oracle with the latest 5.x and 6.x CLIs on the fixture.

Known gaps

Oracle, SQLite and Prisma 5 and 6 facts

Context

The contract's facts were checked against Prisma's SQL by hand in the investigation; step G1B4 commits the oracle, adds SQLite (developer decision 2026-11-09: sqlite facts become oracle where a SQLite oracle agrees), runs Prisma 5.22.0 and 6.19.3 too, and settles G1B3's question on MySQL's AUTO_INCREMENT and SQL Server's IDENTITY (decision 2026-11-09: they are not DEFAULTs).

Options considered

  1. Comparing the claims with Prisma's SQL parsed by Graphvein's migration pass: rejected in the investigation (it would test that pass's coverage).
  2. The real catalog of a database built from Prisma's SQL (chosen): postgresql on the scratch Postgres 17 cluster, sqlite on a scratch SQLite file read through sqlite_master and the pragmas (Python's sqlite3; no SQLite server or CLI is needed).
  3. For runs at another version than a package's pin: a fixture package per version (more golden churn) or the same schema linked with the lockfile's pin rewritten to the run's version (chosen: the test links what Graphvein would claim for a project locked at that version).

Decision

Consequences

Known gaps

Store-side claims projection for /schema/sets

Context

T018g0 (ADR 0058) stores a claims list on every model column. /sets does not serve them (Revision 1) but read every column with Store.Nodes, which decodes each stored payload whole: on langflow (412 model columns, 1.1 MB of column payloads, 0.38 MB without claims) that decode took langflow's /sets from about 50 ms on main (118dd29) to about 68 ms (+30 %), over the 20 % latency gate. /sets needs the claims only to count them by verification (verification_counts).

Options considered

  1. Keep decoding (accepted for T018g0 by option (a); over the gate).
  2. A store read without model claims, and the counts computed in SQL in the same query (SQLite json_each, Postgres json_array_elements). Measured on langflow: the SQLite JSON functions of the pure-Go driver cost as much as the Go decode they replace (json_remove about 4 ms, the per-claim count about 10-13 ms more); /sets was 70 ms, no gain.
  3. A store read without model claims, and the counts stored on the table record when it is written (chosen).
  4. Store claims in their own column or table (schema migration on both backends; more than this needs).

Decision

Consequences

Known gaps

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

Context

The independent review of T018g1 found a provider-dependent fact labelled as if it were provider-independent (A1: SQL Server creates UNIQUE constraints, not unique indexes), a comparator gap in the oracle (B1), partial unique indexes claimed as unconditional (B2), duplicate identities when two packages discover one schema (B3), Prisma 7 schemas that the CLI rejects claimed anyway (C1), and gaps in the API, the view and the assumptions (C2 to C5). Details per finding: the T018g1 task record (internal), "Revision after the independent review (2026-11-09)".

Options considered

Decision

Consequences

The contract rows PR-B1, PR-F1, PR-F2, PR-F4, PR-A2, PR-A3, PR-AA2, PR-R1, PR-R3 and PR-P1 changed (docs and code 1:1, the catalogue golden too). The fixture golden changed (new cases, line shifts). A Prisma 7 project still carrying url in its schema gets no tables, which is what its CLI does.

Known gaps

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

Report a problem with this pageSource: docs/adr/0057-prisma-models.md