Expand description
Provides a framework for SQLite migrations.
Migrations are built as an ordered Migrator with two phases. Retired migrations are retained
as pure SQL and are only used to initialize fresh databases. Active migrations run after the
retired SQL set, remain supported for existing databases, and can be pure SQL or Rust functions.
This lets old active migrations eventually be converted into retired SQL once their upgrade path
no longer needs to be supported.
The database version is stored in SQLite’s PRAGMA user_version. Each migration also has an
expected SchemaHash computed by applying migrations to an in-memory reference database
during builder construction. Bootstrap and runtime migration commit only after the resulting
schema hash matches the expected hash. Normal load paths should use
Migrator::verify_latest_schema before opening their connection pools.
Build migrators manually with Migrator::builder, or generate one from a migration directory
with Migrator::generate in a build.rs. Callers should snapshot Migrator::schema_hashes
in tests to catch accidental schema drift and to prove that retired SQL still produces the same
schema as the active migrations it replaced.
Structs§
- Migrator
- Bootstraps, migrates, and verifies versioned SQLite schemas.
- Migrator
Builder - Builds a
Migratorwhile computing expected schema hashes on an in-memory database. - Schema
Hash - A schema fingerprint computed from ordered entries in
sqlite_schema. - Schema
Hashes
Type Aliases§
- Code
Migration Fn - A Rust migration function executed inside a SQLite transaction.