Skip to main content

Runner

Struct Runner 

Source
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>

Source

pub const fn new(db: &'a Database) -> Self

Creates a new Runner bound to the given database.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a> Freeze for Runner<'a>

§

impl<'a> !RefUnwindSafe for Runner<'a>

§

impl<'a> Send for Runner<'a>

§

impl<'a> Sync for Runner<'a>

§

impl<'a> Unpin for Runner<'a>

§

impl<'a> UnsafeUnpin for Runner<'a>

§

impl<'a> !UnwindSafe for Runner<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.