Documentation

Docs / Reference

ADR 0054 - Model-defined schema

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

Context

Milestone M2 of the project plan accepts "fastapi's SQLModel schema after T018c2" (developer decision D9). T018c1 (ADR 0053) caches the SQLModel/SQLAlchemy model syntax of files that import sqlmodel or sqlalchemy and fixes the claim contract (61 rows, docs/lang/python-models.md); Revision 2 replaced the prediction of import failures with assumption V7 (the model modules import, as they do when the application runs) and rule P1 (failures the pinned source proves from one class stay diagnostics). T018c2 (docs/contract/claims/python-models-linking.md) turns the cached syntax into graph facts. The migration pass (ADR 0047, internal/extract/schema) is being changed in parallel by T018a2, and the schema read API (ADR 0048) and the Schema view (T018b2) derive every set state from migration nodes.

Options considered

  1. Feed model classes into the migration state of internal/extract/schema as another front end (the plan's shared-state idea). Rejected for now: the state is built around ordered SQL statements and Postgres refusal rules that do not apply to a class chain, and T018a2 rewrites that package in parallel.
  2. Merge model tables into the migration sets of the same repository by table name. Rejected: which database a model maps to is runtime configuration (the engine URL), so a merge would assert a fact source does not show; the plan asks to compare, never merge silently.
  3. A separate linker package that emits the same node kinds (table, column, contains, foreign_key) with source: "model", its own group key set: "models", and a comparison diagnostic for equal names (chosen).

Decision

Consequences

Known gaps

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

Accepted after T018c2 Revisions 3-3.3 and the merge of main (records: the T018c2 task record (internal), docs/contract/claims/python-models-linking.md).

Report a problem with this pageSource: docs/adr/0054-model-defined-schema.md