Crate migrant_lib [] [src]

migrant_lib

Embeddable migration management

migrant_lib allows defining and embedding management of migration in your shipped app.

fn up(_: DbConn) -> Result<(), Box<std::error::Error>> {
    print!(" Up!");
    Ok(())
}

fn down(_: DbConn) -> Result<(), Box<std::error::Error>> {
    print!(" Down!");
    Ok(())
}

config.use_migrations(vec![
    FileMigration::with_tag("initial")?
        .up("migrations/initial/up.sql")?
        .down("migrations/initial/down.sql")?
        .boxed(),
    FileMigration::with_tag("second")?
        .up("migrations/second/up.sql")?
        .down("migrations/second/down.sql")?
        .boxed(),
    FnMigration::with_tag("custom")?
        .up(up)
        .down(down)
        .boxed(),
])?;

Migrations can be defined as files or functions. Migration files must exist at runtime. Migration tags must all be unique. Function migrations must have the signature fn(DbConn) -> Result<(), Box<std::error::Error>>. See the programmable example for a working sample.

Migrations management identical to the migrant cli tool can also be embedded. This method only supports file-base migrations generated by migrant_lib (or migrant cli). See the embedded example for a working sample.

Modules

types

Structs

Config

Project configuration/settings

ConfigInitializer

Project configuration/settings builder to initialize a new config file

DbConn
Error

The Error type.

FileMigration
FnMigration
Migrator

Migration applicator

Enums

DbKind

Database type being used

Direction

Represents direction to apply migrations. Up -> up.sql Down -> down.sql

ErrorKind

The kind of an error.

Traits

Migratable
ResultExt

Additional methods for Result, for easy interaction with this crate.

Functions

edit

Open a migration file containing tag in its name

list

List the currently applied and available migrations under migration_location

new

Create a new migration with the given tag

search_for_config

Search for a .migrant.toml file in the current and parent directories

shell

Open a repl connection to the given Config settings

Type Definitions

Result

Convenient wrapper around std::Result.