pub trait Operation<DB>: Send + Syncwhere
DB: Database,{
// Required method
fn up<'life0, 'life1, 'async_trait>(
&'life0 self,
connection: &'life1 mut <DB as Database>::Connection,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn down<'life0, 'life1, 'async_trait>(
&'life0 self,
connection: &'life1 mut <DB as Database>::Connection,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn is_destructible(&self) -> bool { ... }
}
Expand description
Trait for defining a database operation.
An Operation represents action that can be applied to or reverted from a database during a migration. Each operation can have an up method for applying the change and an optional down method for rolling it back.
Operations can also specify whether they are destructible meaning that they require user confirmation before being applied, due to potential data loss or irreversible changes
Required Methods§
Sourcefn up<'life0, 'life1, 'async_trait>(
&'life0 self,
connection: &'life1 mut <DB as Database>::Connection,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn up<'life0, 'life1, 'async_trait>(
&'life0 self,
connection: &'life1 mut <DB as Database>::Connection,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The up method executes the operation when applying the migration.
This method is called when the migration is being applied to the database. Implement this method to define the changes you want to apply.
Provided Methods§
Sourcefn down<'life0, 'life1, 'async_trait>(
&'life0 self,
connection: &'life1 mut <DB as Database>::Connection,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn down<'life0, 'life1, 'async_trait>(
&'life0 self,
connection: &'life1 mut <DB as Database>::Connection,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The down method reverses the operation when rolling back the migration.
This method is called when the migration is being rolled back. Implement this method if you want to make the operation reversible. If not implemented, the operation is considered irreversible.
Sourcefn is_destructible(&self) -> bool
fn is_destructible(&self) -> bool
Indicates whether the up
operation is destructible.
If the operation is destructible, the user will be prompted for
confirmation before running the migration via the CLI, due to the
potential for data loss or irreversible changes. By default, up
operations are considered non-destructible. Note that down
operations
are always considered destructible and cannot be changed.