Skip to main content

MigrationRunner

Trait MigrationRunner 

Source
pub trait MigrationRunner: Send + Sync {
    // Required methods
    fn execute_migration<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        tenant: &'life1 TenantContext,
        plan: &'life2 MigrationPlan,
    ) -> Pin<Box<dyn Future<Output = Result<MigrationResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn acquire_lock<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tenant: &'life1 TenantContext,
        timeout_secs: u64,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn LockGuard + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn validate_migration<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        tenant: &'life1 TenantContext,
        plan: &'life2 MigrationPlan,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Migration runner trait for executing schema changes

This trait abstracts the execution of schema migrations. Different implementations can support:

  • SQL file-based migrations
  • Rust code-based migrations
  • External tool integration (diesel, sqlx migrations)
  • Custom migration strategies

§Design Rationale

Separating migration execution from inspection allows:

  • Pluggable migration engines
  • Different migration strategies per database
  • Testing with mock runners
  • Support for external migration tools

Required Methods§

Source

fn execute_migration<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tenant: &'life1 TenantContext, plan: &'life2 MigrationPlan, ) -> Pin<Box<dyn Future<Output = Result<MigrationResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute a migration plan for a tenant

§Arguments
  • tenant - The tenant context
  • plan - The migration plan to execute
§Errors

Returns an error if:

  • Migration execution fails
  • Transaction rollback is needed and fails
  • Lock acquisition fails
Source

fn acquire_lock<'life0, 'life1, 'async_trait>( &'life0 self, tenant: &'life1 TenantContext, timeout_secs: u64, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn LockGuard + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acquire a lock for a tenant schema

This prevents concurrent migrations on the same tenant. The lock should be released when the migration completes or fails.

§Arguments
  • tenant - The tenant context
  • timeout - Maximum time to wait for lock (in seconds)
§Returns

Returns a lock guard that will release the lock when dropped. The lock guard must be explicitly released by calling release().

Source

fn validate_migration<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tenant: &'life1 TenantContext, plan: &'life2 MigrationPlan, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Check if a migration can be executed safely

This performs pre-flight checks like:

  • Verifying the tenant schema exists
  • Checking for blocking operations
  • Validating migration plan compatibility

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§