MigrationTask

Type Alias MigrationTask 

Source
pub type MigrationTask = Box<dyn Fn(Database) -> BoxFuture<'static, Result<(), Error>> + Send + Sync>;
Expand description

Type alias for migration tasks (e.g., Create Table, Add Foreign Key).

Migration tasks are async closures that take a Database instance and return a boxed future that resolves to a Result. This allows for flexible, composable migration operations.

§Type Definition

type MigrationTask = Box<
    dyn Fn(Database) -> BoxFuture<'static, Result<(), sqlx::Error>> + Send + Sync
>;

§Parameters

  • Database - Cloned database instance for the migration operation

§Returns

  • BoxFuture<'static, Result<(), sqlx::Error>> - Async result of the migration

§Traits

  • Send - Can be safely sent between threads
  • Sync - Can be safely shared between threads

§Example

let task: MigrationTask = Box::new(|db: Database| {
    Box::pin(async move {
        db.create_table::<User>().await?;
        Ok(())
    })
});

Aliased Type§

pub struct MigrationTask(/* private fields */);