Skip to main content

Migrator

Struct Migrator 

Source
pub struct Migrator<'a> { /* private fields */ }
Expand description

Applies JSON migrations through Db.

Implementations§

Source§

impl Migrator<'_>

Source

pub async fn inspect_recovery(&self) -> Result<RecoveryReport, MigrationError>

Inspect recovery bookkeeping using SELECT statements only.

Args: self: Migrator with the database and current migration graph.

Returns: Recorded history/progress and file-checksum match information. Missing tables produce empty lists and are never created here.

§Errors

Unsupported backend, unreadable catalogs/tables or malformed rows.

Source§

impl Migrator<'_>

Source

pub async fn lock_holder(&self) -> Result<Option<LockHolder>, Error>

Identify the session currently holding the migration lock.

Intended for the MigrationError::LockTimeout path: it takes no lock and changes nothing, and the holder may finish between the timeout and this read.

Returns: The holder, or None when the lock is free (or on SQLite, which has no migration lock).

§Errors

Unsupported backend or unreadable catalogs.

Source§

impl<'a> Migrator<'a>

Source

pub fn new(db: &'a Db, graph: &'a MigrationGraph) -> Self

Plan and execute using graph.

Source

pub fn with_registry(self, registry: MigrationRegistry) -> Self

Register RunRust functions used by the planned migrations.

Source

pub fn with_lock_timeout( self, timeout: Duration, ) -> Result<Self, MigrationError>

Set the advisory lock acquisition deadline (default: 30 seconds).

Args: timeout: Positive, representable PostgreSQL/MySQL lock wait.

Returns: This migrator with the new acquisition policy.

Pool acquisition and SQLite BEGIN use backend deadlines. This limit does not bound migration execution after the lock is held.

§Errors

Zero or a duration that overflows the runtime clock.

Source

pub async fn plan_forward( &self, target: Option<&str>, ) -> Result<Vec<String>, MigrationError>

Ids that would be applied to reach target (None = all remaining).

§Errors

Checksum mismatch, unknown target, graph/state errors, or backend errors while reading the history table.

Source

pub async fn migrate( &self, target: Option<&str>, dry_run: bool, ) -> Result<Report, MigrationError>

Apply unapplied migrations up to target (None = all).

dry_run returns the SQL without executing it (history is still read).

§Errors

See Migrator::plan_forward; also statement execution errors.

Source

pub async fn rollback( &self, target: Option<&str>, steps: Option<u32>, dry_run: bool, ) -> Result<Report, MigrationError>

Unapply migrations. target is the id that should remain the head (everything after it is rolled back). steps unapplies that many of the most recently applied visible migrations. Exactly one of the two must be set unless steps is Some(n).

§Errors

Irreversible migrations, checksum mismatch, unknown target, backend errors.

Source

pub async fn show(&self) -> Result<Vec<(String, bool)>, MigrationError>

Every loaded migration with its applied flag (including replaced ids).

§Errors

History-table or checksum errors.

Auto Trait Implementations§

§

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

§

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

§

impl<'a> Freeze for Migrator<'a>

§

impl<'a> Send for Migrator<'a>

§

impl<'a> Sync for Migrator<'a>

§

impl<'a> Unpin for Migrator<'a>

§

impl<'a> UnsafeUnpin for Migrator<'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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more