pub struct Migrator<'a> { /* private fields */ }Expand description
Applies JSON migrations through Db.
Implementations§
Source§impl Migrator<'_>
impl Migrator<'_>
Sourcepub async fn inspect_recovery(&self) -> Result<RecoveryReport, MigrationError>
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<'_>
impl Migrator<'_>
Sourcepub async fn lock_holder(&self) -> Result<Option<LockHolder>, Error>
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>
impl<'a> Migrator<'a>
Sourcepub fn new(db: &'a Db, graph: &'a MigrationGraph) -> Self
pub fn new(db: &'a Db, graph: &'a MigrationGraph) -> Self
Plan and execute using graph.
Sourcepub fn with_registry(self, registry: MigrationRegistry) -> Self
pub fn with_registry(self, registry: MigrationRegistry) -> Self
Register RunRust functions used by the planned migrations.
Sourcepub fn with_lock_timeout(
self,
timeout: Duration,
) -> Result<Self, MigrationError>
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.
Sourcepub async fn plan_forward(
&self,
target: Option<&str>,
) -> Result<Vec<String>, MigrationError>
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.
Sourcepub async fn migrate(
&self,
target: Option<&str>,
dry_run: bool,
) -> Result<Report, MigrationError>
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.
Sourcepub async fn rollback(
&self,
target: Option<&str>,
steps: Option<u32>,
dry_run: bool,
) -> Result<Report, MigrationError>
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.