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 (TEXT ↔
character varying ↔ character 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§
- Schema
Column - Declared shape of one entity column.
- Schema
Mismatch - All divergences found for one table.
- Table
Schema - Declared shape of an entity’s table.
Enums§
- Schema
Check Error - Errors from the assertion itself (query failure vs. actual drift).
- Schema
Drift - One detected divergence between the entity and the live table.
Functions§
- assert_
table - Compare a declared table shape against the live database.