Documentation

Schema from SQLModel models

ADR 0054 (T018c2, docs/contract/claims/python-models-linking.md) and ADR 0058 (T018g0, the T018g0 task record (internal)). The SQLModel front end internal/extract/models/sqlmodel runs at link time, after the migration pass (docs/extract/schema.md), over the model syntax the Python extractor caches (ADR 0053, docs/lang/python-models.md), and hands its tables to the tool-neutral model kit internal/extract/models, which resolves foreign keys (L4), compares with migration sets (L5) and emits the records (L3) for every ORM front end. It adds no cached payload; it ran from extractors-29 on (aggregate extractors-30 since T018f, extractors-31 since T018g0, extractors-32 since T018g2's TypeScript model payload, extractors-33 since T018h's Python and sqlx query payloads, extractors-34 since T018h's binding change, extractors-35 since T018g3's model payload version 2, extractors-36 since T018g5's Go model payload, extractors-37 since T018g6's model payload version 5, extractors-38 since T021's best-effort payload, extractors-39 since T020 S1's Go structure payload, extractors-40 since T020 S2's Python structure payload, extractors-41 since T020 S3's TypeScript structure payload, extractors-42 since T020 S4's Rust structure payload, extractors-43 since T020 S2X's Python workspace members, extractors-44 since GORM's package selection, extractors-45 since T020-TSG's patched grammars, extractors-46 since T023's Go router payload, extractors-47 since T022 MR-B3b's stored Express equivalence and per-alternative client bases and MR-B6c's build-time constant bases, extractors-48 since T026's architecture payloads, ADR 0079, extractors-49 since T024's Next.js and server action payloads, ADR 0077).

What it claims

The claim contract is T018c1's table (docs/lang/python-models.md, "Claim contract", read in its claim and refusal columns with Revision 2: I1 and I2 after v1, assumption V7, rule P1) plus T018c2's linking rows L1-L8 (docs/contract/claims/python-models-linking.md). Every fact comes from one row; everything else is unknown (null) with a reason, and a library default is claimed only where the class and its proven chain show the setting absent.

Records

The schema read API (/api/v0/schema/*) serves model tables as model groups beside the migration sets, grouped by their stored set and never merged with a migration set (T018f, ADR 0055; docs/cli/serve.md "Schema endpoints"); /api/v0/schema/assumptions lists this contract's rows and assumptions (catalogue.go, checked by TestCatalogue).

Claim contract

Row ids of T018c1's table and T018c2's linking rows, with the function that holds each row's claim branch (TestModelClaimContract keeps this table, the task files and the code 1:1).

id claim branch claim (summary; the task files hold the full rows)
C1 class a table for a table=True class whose direct bases are proven non-table
C1b class no table
C1c class none; schema_model_flag_unknown
C2 buildTable chain members contribute columns, nearest definition wins
C3 class none; schema_model_not_claimed
C4 class none (D)
C5 buildTable nothing; outside K-cfg the class is D
C6 buildTable columns and constraints partial; name only from the class's own __tablename__
N1 buildTable table name as written
N2 buildTable Class.lower() when absence is proven
N3 buildTable no table node; schema_model_name_unknown
M0 none nothing (not captured)
M1 buildTable nothing; outside K-dec the class is D
M2 fieldColumn a column from Field(...)
M3 fieldColumn a required column without default
M4 fieldColumn a column with a literal default
M5 fieldColumn no column (removes an inherited field)
M6 fieldColumn nothing
M7 buildTable nothing
M8 buildTable nothing (C5)
M9 buildTable nothing (C5)
M10 buildTable nothing; other keys make the class D
M11 buildTable table constraints and schema
M12 buildTable class D, the bound column unknown; a literal value is P1 (L7)
A1 annotation nullable
A2 annotation not nullable
A3 annotation nullability and type unknown
A5 annotation the alias read in its module
A1m annotation non-plain metadata: column D
F1 fieldCall flags; absent: false
F2 fieldCall nullability
F3 fieldCall default absent or scalar
F3b fieldCall default callable
F4 fieldCall foreign key (last-dot split)
F5 setType type from the annotation
F6 fieldCall type from sa_type
F7 fieldCall the column is the Column(...)
F7r fieldCall P1 failure
F8 fieldCall column D
F9 fieldCall no fact; outside the signature P1
K1 columnCall column name and type
K1b typeExpr type unknown; (Rev 3.3) form alias (a module-level name bound once to a T1 call followed only by .with_variant(...) calls): the column read, its type unknown with reason
K2 columnCall flags, nullable = not primary_key
K3 columnCall foreign key
K4 columnCall default, server default
K5 columnCall nothing
K6 columnCall column D
T1 typeExpr type class with length/timezone
TA1 tableArgs unique constraint
TA2 tableArgs index
TA3 tableArgs check constraint
TA-D tableArgs constraint set, schema and primary key unknown
U1 class none; schema_model_not_claimed (also for a subclass of a declarative class)
U2 buildTable class or column D
U3 Link count in schema_model_core_tables
U4 Link count in schema_model_core_tables
X1 site set or facts not complete; (Rev 3.1) forms PK (primary key open), FK (foreign keys unknown), replace (columns unknown), table_attr (schema and listed elements unknown); (Rev 3.2) forms table_identity (an attribute assignment that may rename the table: schema_model_not_claimed, no table) and column_identity (one that may rename a column: no column node)
U5 site ddl_hooks: true
I1 none after v1 (V7, P1)
I2 none after v1
D class none; partial with reason D
L1 resolve resolution through the Python resolver; (Rev 3.3) the K-dec builtins classmethod, staticmethod, property only when unbound
L2 class cross-file chain and base proof
L3 emit table and column nodes, contains edges
L4 resolveForeignKeys foreign_key edges
L5 compareMigrations schema_model_migration_overlap
L6 Link schema_model_unread, schema_model_core_tables
L7 buildTable schema_model_import_failure, no table (forms F7r, F4, F9, F5, primary key, M12)
L8 site site receivers, test scope

Tests

internal/extract/models/sqlmodel: TestModelClaimContract (rows, docs and tags 1:1; each form of L7 reached; the kit's helpers in internal/extract/models/modeltest), TestModelClaims (claims per known fact, rows per fact, verification), unit tests per linking row, TestStepIsolation (a failing step leaves the others linked), TestModelLinkFixture (graph golden of testdata/fixtures/sqlmodel-link), and TestModelOracle (skipped unless GRAPHVEIN_MODEL_ORACLE and GRAPHVEIN_MODEL_ORACLE_ROOT are set), which compares the claims with scripts/oracle/sqlmodel_metadata.py's output. TestSQLModelFixture (internal/lang/python) holds the graph golden of testdata/fixtures/sqlmodel-models. The kit (internal/extract/models) has its own tests over a tool-neutral record set: TestLink (group key, dialect only when stated, claims with file, span and verification, no claim on a null fact or an unknown column, schema-aware foreign keys), TestForeignKeySchema, TestStepsGuard and TestCatalogues.

Report a problem with this pageSource: docs/extract/schema-models.md