Struct migrant_lib::config::Config [] [src]

pub struct Config { /* fields omitted */ }

Full project configuration

Methods

impl Config
[src]

[src]

Define an explicit set of Migratable migrations to use.

When using explicit migrations, make sure they are defined on the Config instance before applied migrations are loaded from the database. This is required because tag format requirements are stricter for implicit (file-system based) migrations, requiring a timestamp to maintain a deterministic order.

Example

extern crate migrant_lib;
use migrant_lib::{
    Config, search_for_settings_file,
    EmbeddedMigration, FileMigration, FnMigration
};

mod migrations {
    use super::*;
    pub struct Custom;
    impl Custom {
        pub fn up(_: migrant_lib::DbConn) -> Result<(), Box<std::error::Error>> {
            print!(" <[Up!]>");
            Ok(())
        }
        pub fn down(_: migrant_lib::DbConn) -> Result<(), Box<std::error::Error>> {
            print!(" <[Down!]>");
            Ok(())
        }
    }
}

let p = search_for_settings_file(&std::env::current_dir()?)
    .ok_or_else(|| "Settings file not found")?;
let mut config = Config::from_settings_file(&p)?;
config.use_migrations(vec![
    EmbeddedMigration::with_tag("initial")?
        .up(include_str!("../migrations/embedded/initial/up.sql"))
        .down(include_str!("../migrations/embedded/initial/down.sql"))
        .boxed(),
    FileMigration::with_tag("second")?
        .up("migrations/embedded/second/up.sql")?
        .down("migrations/embedded/second/down.sql")?
        .boxed(),
    FnMigration::with_tag("custom")?
        .up(migrations::Custom::up)
        .down(migrations::Custom::down)
        .boxed(),
])?;

// Load applied migrations
let config = config.reload()?;

[src]

Migrations are explicitly defined

[src]

Do a full reload of the configuration file (only if a settings file is being used) and query the database to load applied migrations, keeping track of manually specified migrations.

[src]

Load config file from the given path without querying the database to check for applied migrations

[src]

Initialize a Config using an explicitly created Settings object. This alleviates the need for a settings file.

let settings = Settings::configure_sqlite()
    .database_path("/absolute/path/to/db.db")?
    .migration_location("/absolute/path/to/migration_dir")?
    .build()?;
let config = Config::with_settings(&settings);
// Setup migrations table
config.setup()?;

// Reload config, ping the database for applied migrations
let config = config.reload()?;

[src]

Initialize a new settings file in the given directory

[src]

Confirm the database can be accessed and setup the database migrations table if it doesn't already exist

[src]

Return the absolute path to the directory containing migration folders

[src]

Return the database type

[src]

Return the absolute path to the database file. This is intended for sqlite databases only

[src]

Generate a database connection string. Not intended for file-based databases (sqlite)

Trait Implementations

impl Debug for Config
[src]

[src]

Formats the value using the given formatter.

impl Clone for Config
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more