Skip to main content

Module schema

Module schema 

Source
Expand description

Runtime schema assertion for derived entities.

Generated repositories build their SQL from entity metadata, so a drifted table (renamed column, missed migration, nullability change) surfaces as a runtime decode error instead of a compile error. This module restores an equivalent guarantee with one integration test: compare every entity’s declared columns against information_schema.columns and report all mismatches at once.

#[sqlx::test]
async fn schema_matches(pool: PgPool) {
    User::assert_schema(&pool).await.expect("users drifted");
    Parcel::assert_schema(&pool).await.expect("parcels drifted");
}

§Type comparison

Declared SQL types are normalised before comparison (TEXTcharacter varyingcharacter are one text family; parametrised types drop their arguments; arrays compare as arrays). Columns whose database type is USER-DEFINED (Postgres enums, domains) skip the type check — the macro cannot know the enum’s SQL name unless #[column(pg_enum = ...)] is used, and presence + nullability still guard those columns.

Structs§

SchemaColumn
Declared shape of one entity column.
SchemaMismatch
All divergences found for one table.
TableSchema
Declared shape of an entity’s table.

Enums§

SchemaCheckError
Errors from the assertion itself (query failure vs. actual drift).
SchemaDrift
One detected divergence between the entity and the live table.

Functions§

assert_table
Compare a declared table shape against the live database.