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

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

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

Fields

tag: Stringup: Option<T>down: Option<U>

Implementations

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]

pub fn with_tag(_tag: &str) -> DatabaseFeatureRequired[src]

Create a new FnMigration with the given tag

pub fn up(&mut self, f_up: T) -> &mut Self[src]

Function to use for up migrations

Function must have the signature fn(ConnConfig) -> std::result::Result<(), Box<dyn std::error::Error>>.

pub fn down(&mut self, f_down: U) -> &mut Self[src]

Function to use for down migrations

Function must have the signature fn(ConnConfig) -> std::result::Result<(), Box<dyn std::error::Error>>.

pub fn boxed(&self) -> Box<dyn Migratable>[src]

Box this migration up so it can be stored with other migrations

Trait Implementations

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

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

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]

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

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.