Crate dbmigrator

Source
Expand description

Powerful SQL migration toolkit for Rust.

TODO - Work in progress… DO NOT USE IN PRODUCTION - COME BACK IN 2025 JANUARY.

dbmigrator makes running migrations for different databases as easy as possible. It works by running your migrations on a provided database connection, either by embedding them on your Rust code, or via dbmigrator_cli.
Currently, Postgres, are supported.
Planned Mysql.\

dbmigrator works with .sql file migrations.

§Usage

  • Migrations can be defined in .sql files.
  • Migrations must be named in the format {1}_{2}.sql where {1} represents the migration version, {2} migration kind (upgrade, baseline, revert or fixup) and name.
  • Migrations can be run either by embedding them on your Rust code with embed_migrations! macro (TODO), or via dbmigrator_cli.

§Example

use rusqlite::Connection;

mod embedded {
    use dbmigrator::embed_migrations;
    embed_migrations!("./tests/sql_migrations");
}

let mut conn = Connection::open_in_memory().unwrap();
embedded::migrations::runner().run(&mut conn).unwrap();

for more examples refer to the examples

Structs§

AsyncDriver
Changelog
A migration changelog entry
Config
Migrator
RecipeScript

Enums§

MigratorError
An Error occurred during a migration cycle
RecipeError
An Error occurred during a migration cycle
RecipeKind

Statics§

SIMPLE_FILENAME_PATTERN
Simple regex pattern for {version}_{name}.sql filename naming convention.

Traits§

AsyncClient

Functions§

find_sql_files
Find SQLs on file system recursively across given a location
load_sql_recipes
Loads SQL recipes from a path. This enables dynamic migration discovery, as opposed to embedding.
simple_compare
Default comparator for recipe versions. Usually requires fixed size of version parts.
simple_kind_detector
Simple recipe kind detector, allowing to determine the type of recipe using the recipe name.
version_compare
Compare two versions using the version_compare crate. Allow semver naming conventions.