Documentation

Docs / Reference

ADR 0047 - Schema from sqlx SQL migrations

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

Context

Milestone M2 of the project plan asks for schema extraction from SQL migrations. The T018 plan (the T018 task record (internal)) found raw SQL migrations in two corpora, both sqlx sets on PostgreSQL (axum: 4 files, axum-ddd: 5), and alterations only in the Alembic corpora. T018a (the T018a task record (internal) with Revision 1) defines the first schema extractor. Its investigation stopped once (serial columns would have stated "no default"); Revision 1 added R1-R6 and its R-A assessment (the T018a task record (internal)) found no further stop.

The extractor must never state a wrong schema fact (VISION, principle 6): what it cannot read exactly has to stay visible.

Options considered

Parsing

Where it runs

Discovery

Identity of unqualified and unnamed objects

Partial versus opaque

Decision

internal/extract/schema implements the rules in docs/extract/schema.md: sqlx discovery and file order (Q1-Q5 verified against sqlx v0.5.9 and v0.8.6), the PostgreSQL REL_17_6 statement subset (P1-P5 and R1-R5), a schema state of dialect-neutral operations (unexported until T018c/T018d need it) and emission of:

The index calls it once per link pass after the other linkers; no other linker reads its nodes. Summary.Schema measures the pass. Contract v1 is unchanged: the kinds are extensible (precedents ADR 0036, ADR 0038).

Decisions taken in the implementation (Revision 1 and the T018b1 review questions):

Revision 2 (independent review, the T018a task record (internal) "Revision 2 (review)"):

Revision 3 (re-review, the T018a task record (internal) "Revision 3 (review)"): each finding is closed as a class with a broad conservative rule, preferring over-conservatism to tracking rare dependencies exactly.

Revision 4 (third review, the T018a task record (internal) "Revision 4 (review)"): the same approach, applied to what depends on a key, an index or a column in Postgres.

Revision 5 (re-check of Revision 4, the T018a task record (internal) "Revision 5 (review)"):

Revision 6 (re-check of Revision 5, the T018a task record (internal) "Revision 6 (review)"):

Revision 7 (re-check of Revision 6, the T018a task record (internal) "Revision 7 (review)"; supersedes the Revision 5 and 6 exact-name rules):

Revision 8 (re-check of Revision 7, the T018a task record (internal) "Revision 8 (review)"):

Consequences

Known gaps

Gaps found at the Revision 9 gate, the scope of follow-up task T018a2:

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

Report a problem with this pageSource: docs/adr/0047-sql-migration-schema.md