Struct migrant_lib::config::Config [−][src]
Full project configuration
Implementations
impl Config
[src]
pub fn use_migrations<T: AsRef<[Box<dyn Migratable>]>>(
&mut self,
migrations: T
) -> Result<&mut Self>
[src]
&mut self,
migrations: T
) -> Result<&mut Self>
Define an explicit set of Migratable
migrations to use.
The order of definition is the order in which they will be applied.
Note: When using explicit migrations, make sure any toggling of Config::use_cli_compatible_tags
happens before the call to Config::use_migrations
.
Example
The following uses a migrant config file for connection configuration and
explicitly defines migrations with use_migrations
.
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::ConnConfig) -> Result<(), Box<dyn std::error::Error>> { print!(" <[Up!]>"); Ok(()) } pub fn down(_: migrant_lib::ConnConfig) -> Result<(), Box<dyn 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(&[ EmbeddedMigration::with_tag("create-users-table") .up(include_str!("../migrations/embedded/create_users_table/up.sql")) .down(include_str!("../migrations/embedded/create_users_table/down.sql")) .boxed(), FileMigration::with_tag("create-places-table") .up("migrations/embedded/create_places_table/up.sql")? .down("migrations/embedded/create_places_table/down.sql")? .boxed(), FnMigration::with_tag("custom") .up(migrations::Custom::up) .down(migrations::Custom::down) .boxed(), ])?; // Load applied migrations let config = config.reload()?;
pub fn is_explicit(&self) -> bool
[src]
Migrations are explicitly defined
pub fn use_cli_compatible_tags(&mut self, compat: bool)
[src]
Toggle cli compatible tag validation.
Note: Make sure any calls to Config::use_cli_compatible_tags
happen
before any calls to Config::reload
or Config::use_migrations
since
this is dependent on the tag format being used.
Defaults to false
. When cli_compatible
is set to true
, migration
tags will be validated in a manner compatible with the migrant CLI tool.
Tags must be prefixed with a timestamp, following: [0-9]{14}_[a-z0-9-]+
.
When not enabled (the default), tag timestamps are optional and
the migrant CLI tool will not be able to identify tags.
pub fn is_cli_compatible(&self) -> bool
[src]
Check the current cli compatibility
pub fn reload(&self) -> Result<Config>
[src]
Queries the database to reload the current applied migrations.
Note: Make sure any calls to Config::use_cli_compatible_tags
happen
before any calls to Config::reload
since this is dependent on the
tag format being used.
If the Config
was initialized from a settings file, the settings
will also be reloaded from the file. Returns a new Config
instance.
pub fn from_settings_file<T: AsRef<Path>>(path: T) -> Result<Config>
[src]
Initialize a Config
from a settings file at the given path.
This does not query the database for applied migrations.
pub fn with_settings(s: &Settings) -> Config
[src]
Initialize a Config
using an explicitly created Settings
object.
This alleviates the need for a settings file.
This does not query the database for applied migrations.
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()?;
pub fn init_in<T: AsRef<Path>>(dir: T) -> SettingsFileInitializer
[src]
Initialize a new settings file in the given directory
pub fn setup(&self) -> Result<bool>
[src]
Confirm the database can be accessed and setup the database migrations table if it doesn’t already exist
pub fn migration_dir(&self) -> Result<PathBuf>
[src]
renamed to migration_location
Return the absolute path to the directory containing migration folders
The location returned is dependent on whether an absolute or relative path
was provided to migration_location
in either a settings file or settings builder.
If an absolute path was provided, that same path is returned.
If a relative path was provided, the path returned will be relative
to either the settings file’s directory if a settings file exists, or
the current directory.
pub fn migration_location(&self) -> Result<PathBuf>
[src]
Return the absolute path to the directory containing migration folders
The location returned is dependent on whether an absolute or relative path
was provided to migration_location
in either a settings file or settings builder.
If an absolute path was provided, that same path is returned.
If a relative path was provided, the path returned will be relative
to either the settings file’s directory if a settings file exists, or
the current directory.
pub fn database_type(&self) -> DbKind
[src]
Return the database type
pub fn database_path(&self) -> Result<PathBuf>
[src]
Return the absolute path to the database file. This is intended for sqlite databases only
pub fn connect_string(&self) -> Result<String>
[src]
Generate a database connection string. Not intended for file-based databases (sqlite)
pub fn ssl_cert_file(&self) -> Option<PathBuf>
[src]
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Config
impl !Send for Config
impl !Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,