Expand description
Module for defining the Operation
trait
This module provides the Operation
trait, allowing users to define
database operations that can be executed as part of a migration process.
These operations can be applied (up
) or optionally reverted (down
).
To create own operation implement trait for type
§Example
use sqlx_migrator::error::Error;
use sqlx_migrator::operation::Operation;
use sqlx::Sqlite;
struct ExampleOperation;
#[async_trait::async_trait]
impl Operation<Sqlite> for ExampleOperation {
async fn up(
&self,
connection: &mut sqlx::SqliteConnection,
) -> Result<(), Error> {
// Do some operations
Ok(())
}
// By default operation is irreversible and cannot be reversed if you want to support
// reverse of migration than add down function as well
async fn down(
&self,
connection: &mut sqlx::SqliteConnection,
) -> Result<(), Error> {
// Do some operations
Ok(())
}
}
Traits§
- Operation
- Trait for defining a database operation.