Skip to main content

miden_node_db/migration/
mod.rs

1//! Provides a framework for SQLite migrations.
2//!
3//! Migrations are built as an ordered [`Migrator`] with two phases. Retired migrations are retained
4//! as pure SQL and are only used to initialize fresh databases. Active migrations run after the
5//! retired SQL set, remain supported for existing databases, and can be pure SQL or Rust functions.
6//! This lets old active migrations eventually be converted into retired SQL once their upgrade path
7//! no longer needs to be supported.
8//!
9//! The database version is stored in SQLite's `PRAGMA user_version`. Each migration also has an
10//! expected [`SchemaHash`] computed by applying migrations to an in-memory reference database
11//! during builder construction. Bootstrap and runtime migration commit only after the resulting
12//! schema hash matches the expected hash. Normal load paths should use
13//! [`Migrator::verify_latest_schema`] before opening their connection pools.
14//!
15//! Build migrators manually with [`Migrator::builder`], or generate one from a migration directory
16//! with [`Migrator::generate`] in a `build.rs`. Callers should snapshot [`Migrator::schema_hashes`]
17//! in tests to catch accidental schema drift and to prove that retired SQL still produces the same
18//! schema as the active migrations it replaced.
19
20mod build_script;
21mod builder;
22mod entry;
23mod migrator;
24mod schema;
25
26pub use builder::MigratorBuilder;
27pub use entry::CodeMigrationFn;
28pub use migrator::Migrator;
29pub use schema::{SchemaHash, SchemaHashes};