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

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Define functionality that runs for up migrations

Define functionality that runs for down migrations

A unique identifying tag

Option migration description. Defaults to Migratable::tag

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.