Crate migrant_lib [−] [src]
Embeddable migration management
Also see
migrant
CLI
migrant_lib
allows defining and embedding management of migrations in your compiled application.
Available Features:
Feature | Backend |
---|---|
d-postgres |
Enable postgres connectivity |
d-sqlite |
Enable sqlite connectivity |
d-mysql |
Enable mysql connectivity |
d-all |
Enable all backends |
Note: No features are enabled by default
Usage
- Migrations can be defined as files or functions.
- File migrations can be either read from files at runtime or embedded in your executable at compile time.
- Migration tags must all be unique and may only contain the characters
[a-z0-9-]
. - Function migrations must have the signature
fn(DbConn) -> Result<(), Box<std::error::Error>>
. See the embedded_programmable example for a working sample of function migrations. - When working with embedded and function migrations, the respective database feature must be
enabled (
d-postgres
/d-sqlite
/d-mysql
). - When database features are enabled, the entirety of the database-specific connection library will
be re-exported in the
types
module.
fn up(_: migrant_lib::DbConn) -> Result<(), Box<std::error::Error>> { print!(" Up!"); Ok(()) } fn down(_: migrant_lib::DbConn) -> Result<(), Box<std::error::Error>> { print!(" Down!"); Ok(()) } config.use_migrations(vec![ migrant_lib::FileMigration::with_tag("create-users-table")? .up("migrations/embedded/create_users_table/up.sql")? .down("migrations/embedded/create_users_table/down.sql")? .boxed(), migrant_lib::EmbeddedMigration::with_tag("create-places-table")? .up(include_str!("../migrations/embedded/create_places_table/up.sql")) .down(include_str!("../migrations/embedded/create_places_table/down.sql")) .boxed(), migrant_lib::FnMigration::with_tag("custom")? .up(up) .down(down) .boxed(), ])?;
CLI Compatibility
Migrations management identical to the migrant
cli tool can also be embedded.
This method only supports file-based migrations and those migration files must be generated by migrant_lib::new
(or the migrant
cli). This is required because migration order is implied by file names which must follow
a specific format and contain a valid timestamp.
See the migrant_cli_compatible example for a working sample.
Development
See CONTRIBUTING
Reexports
pub use errors::*; |
pub use config::Config; |
pub use config::Settings; |
pub use migration::FileMigration; |
pub use migration::EmbeddedMigration; |
pub use migration::FnMigration; |
Modules
config |
Configuration structs |
errors |
Error types |
migration |
Embedded / programmable migrations |
types |
Re-exported database-specific drivers |
Structs
DbConn |
Database connection wrapper |
Migrator |
Migration applicator |
Enums
DbKind |
Database type being used |
Direction |
Represents direction to apply migrations.
|
Traits
Migratable |
A type that can be used to define database migrations |
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_settings_file |
Search for a |
shell |
Open a repl connection to the given |