Crate migrant_lib [−] [src]
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(), EmbeddedMigration::with_tag("second")? .up(include_str!("../migrations/second/up.sql")) .down(include_str!("../migrations/second/down.sql")) .boxed(), FnMigration::with_tag("custom")? .up(up) .down(down) .boxed(), ])?;
Migrations can be defined as files or functions. Migrations can be either read from
files at runtime or embedded in your executable at compile time.
Migration tags must all be unique. Function migrations must have the signature
fn(DbConn) -> Result<(), Box<std::error::Error>>
. See the
embedded/programmable example
for a working sample. When working with migrations, the respective database feature must
be enabled (postgresql
/ sqlite
). The entirety of the database-specific connection library will
be re-exported in the types
module.
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
migrant-cli-compatible example
for a working sample.
Modules
types |
Re-exported database-specific drivers |
Structs
Config |
Project configuration/settings |
ConfigInitializer |
Project configuration/settings builder to initialize a new config file |
DbConn |
Database connection wrapper |
EmbeddedMigration |
Define an embedded migration |
Error |
The Error type. |
FileMigration |
Define a migration that uses files |
FnMigration |
Define a programmable migration |
Migrator |
Migration applicator |
Enums
DbKind |
Database type being used |
Direction |
Represents direction to apply migrations.
|
ErrorKind |
The kind of an error. |
Traits
Migratable |
A type that can be used to define database migrations |
ResultExt |
Additional methods for |
Functions
edit |
Open a migration file containing |
list |
List the currently applied and available migrations under |
new |
Create a new migration with the given tag |
search_for_config |
Search for a |
shell |
Open a repl connection to the given |
Type Definitions
Result |
Convenient wrapper around |