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 viadbmigrator_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§
- Async
Driver - Changelog
- A migration changelog entry
- Config
- Migrator
- Recipe
Script
Enums§
- Migrator
Error - An Error occurred during a migration cycle
- Recipe
Error - An Error occurred during a migration cycle
- Recipe
Kind
Statics§
- SIMPLE_
FILENAME_ PATTERN - Simple regex pattern for
{version}_{name}.sql
filename naming convention.
Traits§
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.