Struct migrant_lib::Config
[−]
[src]
pub struct Config { /* fields omitted */ }
Full project configuration
Methods
impl Config
[src]
fn use_migrations(
&mut self,
migrations: Vec<Box<Migratable>>
) -> Result<&mut Self>
[src]
&mut self,
migrations: Vec<Box<Migratable>>
) -> Result<&mut Self>
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/initial/up.sql")) .down(include_str!("../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(migrations::Custom::up) .down(migrations::Custom::down) .boxed(), ])?; // Load applied migrations let config = config.reload()?;
fn is_explicit(&self) -> bool
[src]
Migrations are explicitly defined
fn reload(&self) -> Result<Config>
[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
.
fn from_settings_file<T: AsRef<Path>>(path: T) -> Result<Config>
[src]
Load config file from the given path without querying the database to check for applied migrations
fn with_settings(s: &Settings) -> Config
[src]
Initialize a Config
using an explicitly created Settings
object.
This alleviates the need for a settings file.
let mut settings = Settings::with_db_type(DbKind::Sqlite); settings.database_path("/absolute/path/to/db.db")?; settings.migration_location("/absolute/path/to/migration_dir")?; let config = Config::with_settings(&settings); // Setup migrations table config.setup()?; // Reload config, ping the database for applied migrations let config = config.reload()?;
fn init_in(dir: &Path) -> ConfigInitializer
[src]
Start a config initializer in the given directory
fn setup(&self) -> Result<bool>
[src]
- Confirm the database can be accessed
- Setup the database migrations table if it doesn't exist yet
fn migration_dir(&self) -> Result<PathBuf>
[src]
Return the absolute path to the directory containing migration folders
fn database_type(&self) -> Result<String>
[src]
Return the database type
fn database_path(&self) -> Result<PathBuf>
[src]
Return the absolute path to the database file. This is intended for sqlite3 databases only
fn connect_string(&self) -> Result<String>
[src]
Generate a database connection string. Not intended for file-based databases (sqlite)