Struct migrant_lib::migration::FnMigration [−][src]
Expand description
Define a programmable migration
FnMigration
s are provided a ConnConfig
instance and given free rein to do as they please.
Database specific features (d-postgres
/d-sqlite
/d-mysql
) are required to use this functionality.
Note, both an up
and down
function must be provided. There is a noop function available
(migrant_lib::migration::noop
) for convenience.
Example
fn add_data(config: ConnConfig) -> Result<(), Box<dyn std::error::Error>> {
// do stuff...
Ok(())
}
FnMigration::with_tag("add-user-data")
.up(add_data)
.down(migrant_lib::migration::noop);
Fields
tag: String
up: Option<T>
down: Option<U>
Implementations
Create a new FnMigration
with the given tag
Function to use for up
migrations
Function must have the signature fn(ConnConfig) -> std::result::Result<(), Box<dyn std::error::Error>>
.
Function to use for down
migrations
Function must have the signature fn(ConnConfig) -> std::result::Result<(), Box<dyn std::error::Error>>
.
Box this migration up so it can be stored with other migrations
Trait Implementations
impl<T, U> Migratable for FnMigration<T, U> where
T: 'static + Clone + Fn(ConnConfig<'_>) -> Result<(), Box<dyn Error>>,
U: 'static + Clone + Fn(ConnConfig<'_>) -> Result<(), Box<dyn Error>>,
impl<T, U> Migratable for FnMigration<T, U> where
T: 'static + Clone + Fn(ConnConfig<'_>) -> Result<(), Box<dyn Error>>,
U: 'static + Clone + Fn(ConnConfig<'_>) -> Result<(), Box<dyn Error>>,
Define functionality that runs for up
migrations
Define functionality that runs for down
migrations
Option migration description. Defaults to Migratable::tag
Auto Trait Implementations
impl<T, U> RefUnwindSafe for FnMigration<T, U> where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for FnMigration<T, U> where
T: Send,
U: Send,
impl<T, U> Sync for FnMigration<T, U> where
T: Sync,
U: Sync,
impl<T, U> Unpin for FnMigration<T, U> where
T: Unpin,
U: Unpin,
impl<T, U> UnwindSafe for FnMigration<T, U> where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more