[][src]Struct migrant_lib::migration::FnMigration

pub struct FnMigration<T, U> {
    pub tag: String,
    pub up: Option<T>,
    pub down: Option<U>,
}

Define a programmable migration

FnMigrations 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<std::error::Error>> {
    // do stuff...
    Ok(())
}

FnMigration::with_tag("add-user-data")
    .up(add_data)
    .down(migrant_lib::migration::noop);

Fields

Methods

impl<T, U> FnMigration<T, U> where
    T: 'static + Clone + Fn(ConnConfig) -> Result<(), Box<dyn Error>>,
    U: 'static + Clone + Fn(ConnConfig) -> Result<(), Box<dyn Error>>, 
[src]

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<std::error::Error>>.

Function to use for down migrations

Function must have the signature fn(ConnConfig) -> std::result::Result<(), Box<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>>, 
[src]

impl<T: Clone, U: Clone> Clone for FnMigration<T, U>
[src]

Performs copy-assignment from source. Read more

impl<T: Debug, U: Debug> Debug for FnMigration<T, U>
[src]

Auto Trait Implementations

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

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]