Documentation

Docs / Reference

ADR 0058 - Model-record kit: tool-neutral core, group key, claims and verification

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

Context

ADR 0054 put the SQLModel linker in internal/extract/models: one package that resolves Python model classes and also builds the table and column records, resolves foreign keys (row L4), compares with migration sets (L5), isolates steps and emits the nodes (L3). The 2026-11-09 plan (the T018 task record (internal), "ORMs in the other first-tier languages") adds six more ORM front ends (Prisma first, T018g1), each of which would otherwise copy the emitter. Three developer decisions of 2026-11-09 change the shared record:

This ADR amends ADR 0054's package layout and record shape. It does not change ADR 0054's decisions on what SQLModel claims.

Options considered

  1. Package layout.
    • A. Core in internal/extract/models (package models), SQLModel in internal/extract/models/sqlmodel, later tools beside it (.../prisma, ...) (chosen: the core keeps the package path ADR 0054 named for "models"; every front end imports the core and never the other way round).
    • B. Keep SQLModel in internal/extract/models and put the core in a subpackage (.../kit) (rejected: Prisma would import a SQLModel package's child; the tool-specific package would hold the generic name).
    • C. One package for all tools (rejected: each tool's contract test hooks, row ids and resolver are package state; one package mixes them).
  2. How a front end hands over its tables.
    • A. The front end keeps its own working structs and converts each claimed table into the core's models.Table/models.Column once, after its own steps (chosen: SQLModel's resolution, chain and mutation-site logic stay untouched; the core sees only final records).
    • B. The front ends work on the core's structs directly (rejected for now: SQLModel's structs carry Python-specific state, such as the class record, derived nullability and refused columns; moving them into the core leaks one tool's state into every tool).
  3. Claims.
    • A. The front end records, per fact, the row whose branch set it; the core emits a claim only for a fact that is known in the final record (chosen: a fact held as null can never carry a claim, whatever a front end recorded).
    • B. Claims derived after the fact by fingerprinting (the migration pass's approach; rejected: a class is read in one pass with no statement order, so the branch knows its row directly).
  4. Verification granularity.
    • A. Per claim (column facts) and one value per table for the table's own facts (name, schema, keys, constraint lists) (chosen: table facts carry no claims yet, ADR 0055's known gap; a front end whose table facts mix both values states mapped, the conservative side).
    • B. Per element of every list (each index, each foreign key) (rejected for now: no front end needs it before Prisma's contract review; Prisma may add it with its own ADR).
  5. SQLModel's root.
    • A. The repository root, . (chosen: every SQLModel table registers in the one SQLModel.metadata, assumption V4; L4 resolves foreign keys across the repository; an unresolved production X1 site affects every production table of the repository, L8. The group is the linker's scope, so foreign keys, overlaps and the strip's diagnostics stay exactly as before).
    • B. The Python package root (the topmost directory with __init__.py) or the nearest pyproject.toml (rejected: it would split one MetaData into several groups, so a foreign key between two packages would cross groups, and the .py files' unread and not-claimed diagnostics would need a per-root assignment the server cannot make for a file outside every root).

Decision

Options 1A, 2A, 3A, 4A and 5A.

Revision 1 (2026-11-09)

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

Consequences

Known gaps

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

Report a problem with this pageSource: docs/adr/0058-model-record-kit.md