pub struct Runner<'a> { /* private fields */ }Expand description
Stable migration-runner API seam (extension seam §6b).
Maintains a JSON ledger of applied version numbers in the _meta
collection. The full migration DSL (up/down/backfill) is deferred
to spec §8; this runner provides the version-tracking surface that
the future framework will attach to.
§Examples
use nookdb_core::Database;
use nookdb_core::migrate::Runner;
let db = Database::open(dir.path().join("m.db")).unwrap();
let r = Runner::new(&db);
assert_eq!(r.status().unwrap().current_version, 0);
assert_eq!(r.list_pending(&[1, 2]).unwrap(), vec![1, 2]);
r.run(&[1, 2]).unwrap();
assert_eq!(r.list_applied().unwrap(), vec![1, 2]);
assert_eq!(r.status().unwrap().current_version, 2);Implementations§
Source§impl<'a> Runner<'a>
impl<'a> Runner<'a>
Sourcepub fn list_applied(&self) -> Result<Vec<u32>, NookError>
pub fn list_applied(&self) -> Result<Vec<u32>, NookError>
Returns the list of applied migration version numbers in the order they were applied.
§Errors
Returns NookError::Migration if the ledger is corrupt, or a
storage error if the underlying read fails.
Sourcepub fn status(&self) -> Result<MigrationStatus, NookError>
pub fn status(&self) -> Result<MigrationStatus, NookError>
Returns a snapshot of the current migration state.
§Errors
Returns NookError::Migration if the ledger is corrupt, or a
storage error if the underlying read fails.
Sourcepub fn list_pending(&self, all: &[u32]) -> Result<Vec<u32>, NookError>
pub fn list_pending(&self, all: &[u32]) -> Result<Vec<u32>, NookError>
Returns the versions in all that have not yet been applied,
in the same order as given.
§Errors
Returns NookError::Migration if the ledger is corrupt, or a
storage error if the underlying read fails.
Sourcepub fn run(&self, all: &[u32]) -> Result<(), NookError>
pub fn run(&self, all: &[u32]) -> Result<(), NookError>
Records the pending subset of all as applied (idempotent). M2 has
no real migration-step type yet — this is the no-op-capable runner
that maintains the version ledger.
Already-applied versions in all are silently skipped; the call
is safe to repeat with the same arguments.
Hardened in M5a: read-merge-write happens in a single write
transaction so concurrent runs cannot lost-update the ledger.
See tests/migrate_concurrent.rs.
§Errors
Returns NookError::Migration if the ledger is corrupt or cannot be
serialised, or a storage error if the underlying write fails.