MigrationRunner

Struct MigrationRunner 

Source
pub struct MigrationRunner<'a, Ctx, S>
where S: MigrationStore,
{ /* private fields */ }
Expand description

Runs migrations against a context using a store for tracking.

Generic parameters:

  • Ctx: The context passed to migrations (e.g., database connection)
  • S: The store implementation for tracking applied migrations

Implementations§

Source§

impl<'a, Ctx, S> MigrationRunner<'a, Ctx, S>
where S: MigrationStore,

Source

pub fn new(store: S) -> MigrationRunner<'a, Ctx, S>

Source

pub fn into_store(self) -> S

Consume the runner and return the store

Source

pub fn store(&self) -> &S

Get a reference to the store

Source

pub fn store_mut(&mut self) -> &mut S

Get a mutable reference to the store

Source

pub fn add<M>(self, migration: M) -> MigrationRunner<'a, Ctx, S>
where M: Migration<Ctx> + 'a,

Add a migration

Source

pub fn add_all<I, M>(self, migrations: I) -> MigrationRunner<'a, Ctx, S>
where I: IntoIterator<Item = M>, M: Migration<Ctx> + 'a,

Add multiple migrations

Source

pub fn init(&mut self) -> Result<(), Error>

Initialize store and validate migrations

Source

pub fn current_version(&self) -> Result<u64, Error>

Get current schema version

Source

pub fn status(&self) -> Result<Vec<MigrationStatus>, Error>

Get status of all migrations

Source

pub fn pending(&self) -> Result<Vec<&dyn Migration<Ctx>>, Error>

Get pending (unapplied) migrations

Source

pub fn pending_phase( &self, phase: Phase, ) -> Result<Vec<&dyn Migration<Ctx>>, Error>

Get pending migrations for a specific phase

Source

pub fn migrate(&mut self, ctx: &mut Ctx) -> Result<usize, Error>

Run all pending migrations

Source

pub fn migrate_phase( &mut self, ctx: &mut Ctx, phase: Phase, ) -> Result<usize, Error>

Run pending migrations for a specific phase only

Source

pub fn dry_run(&self) -> Result<DryRunResult, Error>

Dry-run: show what would be applied without actually applying

Source

pub fn dry_run_phase(&self, phase: Phase) -> Result<DryRunResult, Error>

Dry-run for a specific phase

Source

pub fn migrate_to(&mut self, ctx: &mut Ctx, target: u64) -> Result<usize, Error>

Migrate to a specific version (up or down)

Auto Trait Implementations§

§

impl<'a, Ctx, S> Freeze for MigrationRunner<'a, Ctx, S>
where S: Freeze,

§

impl<'a, Ctx, S> !RefUnwindSafe for MigrationRunner<'a, Ctx, S>

§

impl<'a, Ctx, S> Send for MigrationRunner<'a, Ctx, S>
where S: Send,

§

impl<'a, Ctx, S> Sync for MigrationRunner<'a, Ctx, S>
where S: Sync,

§

impl<'a, Ctx, S> Unpin for MigrationRunner<'a, Ctx, S>
where S: Unpin,

§

impl<'a, Ctx, S> !UnwindSafe for MigrationRunner<'a, Ctx, S>

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, 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.