Documentation

Docs / Reference

ADR 0055 - Schema assumptions and model tables in the schema API

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

Context

The schema read API (ADR 0048) serves sqlx migration sets only. Two extractors now state things the Schema view (T018b2) cannot show:

The developer chose the round 2 design R2 on 2026-11-09 (T018f design round 2 mockups, internal): one card per source group in the set strip (a dashed card for a source with nothing read; "Alembic migrations found, not read yet" for a tool Graphvein detects but does not read), a "Rests on" line on the group and the table, row chips only where a row rests on more than its table, one Assumptions tab as the catalogue, and a "why" popover on every fact that is unknown, partial, "as far as the migrations show" or carries a chip. The VISION precision principle applies unchanged: an absence only where the API proves it, unknown shown as unknown, and an assumption visible wherever a fact rests on one.

The view needs facts that are not stored or not served today: which contract row set each fact and where; the opaque statements behind opaque_after; model groups; detected but unread migration tools; the assumption texts and the row table.

Options considered

  1. Where per-fact provenance comes from.
    • A. The extractors store it on the records: migration column and db_index records gain claims: [{fact, row, migration, span}], table reasons gain row, migration records gain opaque_sites; model reasons gain fact and file (chosen). Only the pass knows which statement last set a fact and under which row.
    • B. The server re-derives rows from the fact kind and the history evidence (rejected: a column type can come from M2, M5c or M1b; the server would guess where the pass knows, the precision rule ADR 0048 option 2 forbids).
    • C. Show only table-level assumptions, no per-fact rows (rejected: the developer asked for row chips and per-fact reasons; an index's E2 dependency would be invisible).
  2. Opaque sites per table or per migration.
    • A. Each migration record stores its own opaque statements (opaque_sites: [{span, row, kind}]), and the API lists, per table, the set's sites after the table's CREATE (chosen: stored once; the table list follows from data already stored).
    • B. Each table stores its own list (rejected: every opaque statement is repeated on every table created before it; store size grows with tables x statements).
  3. Model tables in the API (PD1).
    • A. Groups per source: source: "models" beside the migration groups in /sets, with model-specific fields and the same derived completeness vocabulary (chosen; ADR 0048 option 3 reserved the field).
    • B. A separate /api/v0/schema/models endpoint (rejected: the view would join two responses that can come from different index runs).
    • C. Keep them out (rejected by the developer's R2 decision).
  4. Overlap between a model table and a migration table (PD2).
    • A. Derived by the server with L5's rule (exact name equality; the column-name difference only when both tables are complete), exposed on both tables, checked against the stored schema_model_migration_overlap diagnostics in a test (chosen: no message parsing, both directions from one rule).
    • B. Parse the diagnostic's message (rejected: messages are text, ADR 0048 never parses them).
    • C. Store an attribute on the model table (rejected for now: a record change in T018c2's area for data the server can derive exactly; it would still give only one direction).
  5. Detected but unread tools.
    • A. unread_tools on /summary and /sets, derived from stored file paths by a fixed marker rule (chosen: the scanner already stores every file it reads; no extractor change).
    • B. A detector pass that emits records (rejected: a new record kind for a hint that changes no fact).
  6. Assumption catalogue.
    • A. GET /api/v0/schema/assumptions built from Go tables in the extractor packages (texts plus the row table), checked against the documents (chosen: one source, served once per page load).
    • B. Texts in the web bundle (rejected: a second copy that drifts from contractAssumptions and the docs).
    • C. Texts repeated on every fact (rejected: size).
  7. Where the assumptions are shown (UI).
    • A. R2: "Rests on" lines, row chips where a row differs, popovers, the Assumptions tab (chosen by the developer, 2026-11-09).
    • B. Round 1 variant 3's right-hand "rests on" rail beside the detail (considered; kept as a documented option, not built in v1). The rail needs no API field beyond those the popovers use. Design, toggle, measurements and the sources to rebuild it are in the T018f rail-option mockup (internal).

Decision

Options 1A, 2A, 3A, 4A, 5A, 6A and 7A. The exact shapes are in the T018f task record (internal) Part 1; summarised:

Consequences

Implementation notes (T018f Part 1)

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

Store read by code (T018f, 2026-11-09)

The B1 rule and the model group counts read the .py files' diagnostics. Reading them by file (Diagnostics over ~4,100 langflow files, 33 chunked queries, ~3,400 decoded unresolved_calls) cost most of /schema/sets. The store interface gains one read, DiagnosticsWithCodes(ctx, repository, codes, prefixes): the diagnostics, in stored order, whose code is in codes or starts with a prefix, on any file. Both drivers read the code from the stored payload in SQL (json_extract on SQLite, ->> on Postgres) and check the decoded code again in Go, so the result is exact. The server keeps the diagnostics of stored .py files among them (schema_ codes and the unread codes), which are all the model rules read; responses are unchanged. Options considered: a code column on diagnostics with an index (rejected here: a schema migration for ~5 ms; reconsider if more views filter by code); a per-run response cache (not taken: the API is documented as uncached; left to the developer).

Known gaps

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

Accepted after T018f Parts 1-2, Revisions 1 and 2 and steps f6 and f7 (records: the T018f task records (internal)).

Amendment (T018g6 Revision 4, 2026-11-15; status unchanged)

The model rows of /api/v0/schema/assumptions are now served per tool (ADR 0064): rows["models/<tool>"] for drizzle, prisma, sequelize, sqlmodel and typeorm, each with its own default row D, and every row carries a tool field (null on migration rows). rows.models is no longer served, because the tools share row ids (D, and any id two contracts might reuse) and one key per id gave one tool's summary to another tool's rows.

Deep links written before the change keep working: the web reads an Assumptions tab entry a=row:models:<id> as row:models/sqlmodel:<id> (SQLModel's rows were the only model rows rows.models served; web/src/sections/schema/params.ts, parseSchemaParams), so an old #/schema?tab=assumptions&a=row:models:M1 opens SQLModel's row M1.

Report a problem with this pageSource: docs/adr/0055-schema-assumptions-and-model-tables-in-the-api.md