migrant_lib

Build Status crates.io:migrant_lib docs

Embeddable migration management

Also see migrant CLI

migrant_lib allows defining and embedding management of database migrations and (connection) configuration 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

```rust fn up(: migrantlib::ConnConfig) -> Result<(), Box> { print!(" Up!"); Ok(()) }

fn down(: migrantlib::ConnConfig) -> Result<(), Box> { print!(" Down!"); Ok(()) }

config.usemigrations(&[ migrantlib::FileMigration::withtag("create-users-table")? .up("migrations/embedded/createuserstable/up.sql")? .down("migrations/embedded/createuserstable/down.sql")? .boxed(), migrantlib::EmbeddedMigration::withtag("create-places-table")? .up(includestr!("../migrations/embedded/createplacestable/up.sql")) .down(includestr!("../migrations/embedded/createplacestable/down.sql")) .boxed(), migrantlib::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 migrantclicompatible example for a working sample.

Development

See CONTRIBUTING


License: MIT