Skip to main content

Module contract_validator

Module contract_validator 

Source
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)

CaseSeverity
Missing tableERROR
Missing columnERROR
Type mismatchERROR
Nullability driftERROR
Wrong primary keyERROR
Extra DB columnWARNING

§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 IssueKind variants 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§

SchemaIssue
One drift point — column-scoped or table-scoped (column = None).
SchemaReport
Validation result for one model.

Enums§

IssueKind
Discrete failure mode for a single drift point.
ReportStatus
Overall outcome of one model’s validation pass. Computed from the error/warning counts in SchemaReport and 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.