Expand description
Schema Contract runtime validator (Phase 14, commit 3).
Compares a Rust ModelSchema
contract against the actual PostgreSQL schema, surfacing every
drift point as a structured SchemaIssue.
§Architecture
Rust ModelSchema (compile-time contract) Postgres information_schema (live)
│ │
└────────────────► validator ◄───────────────────┘
│
▼
SchemaReport
{ errors, warnings, status }The validator is read-only: it issues two SELECT statements
against information_schema per model and never mutates the
database. Safe to run on a production replica.
§What it detects (per the spec)
| Case | Severity |
|---|---|
| Missing table | ERROR |
| Missing column | ERROR |
| Type mismatch | ERROR |
| Nullability drift | ERROR |
| Wrong primary key | ERROR |
| Extra DB column | WARNING |
§What it does NOT do (yet)
- No human-readable rendering (commit 4 wires this through
rustio doctor --check-schema --json). - No CHECK-constraint introspection, no column DEFAULT
comparison, no FK validation. These can be added with new
IssueKindvariants without breaking the report shape. - No caching. Each call re-queries
information_schema.
§Phase scope
Commit 3 ships only the validator + types + PG-gated tests.
Nothing in admin/, search/, migrations, or cli/
references this module yet.
Structs§
- Schema
Issue - One drift point — column-scoped or table-scoped (
column = None). - Schema
Report - Validation result for one model.
Enums§
- Issue
Kind - Discrete failure mode for a single drift point.
- Report
Status - Overall outcome of one model’s validation pass. Computed from
the error/warning counts in
SchemaReportand stored explicitly so consumers don’t have to recompute.
Functions§
- validate_
all - Validate every schema in the given slice. Sequential — running in parallel would saturate the connection pool with introspection queries that are usually cheap individually but multiply when every model is checked at once.
- validate_
schema - Validate the schema of a single model against the live DB.