Refinery Logo

Powerful SQL migration toolkit for Rust.
MIT licensed
Build Status

refinery 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 refinery_cli.
currently Postgres, Rusqlite and Mysql are supported.
refinery works best with Barrel but you can also have your migrations on .sql files or use any other Rust crate for schema generation.


  • Migrations can be defined in .sql files or Rust modules that must have a function called migration that returns a String
  • Migrations, both .sql files and Rust modules must be named in the format V{1}__{2}.rs where {1} represents the migration version and {2} the name.
  • Migrations can be run either by embedding them on your Rust code with embedded_migrations and include_migration_mods macros, or via refinery_cli.


use ttrusqlite::Connection;

mod embedded {
    use refinery::embed_migrations;

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

for more examples refer to the examples

Implementation details

Refinery works by creating a table that keeps all the applied migrations versions and it’s metadata. When you run the migrations Runner, Refinery compares the applied migrations withe the ones to be applied, checking for divergent and missing and executing unapplied migrations


Refinery’s design is based on flyway and so, shares it’s perspective on undo/rollback migrations. To undo/rollback a migration you have to generate a new one and write specificaly what you want to undo.


Refinery aims to support stable Rust, the previous Rust version, and nightly


while Refinery plans to offer async migrations, for now the best way to run migrations on an async context is to run them inside something like tokio’s spawn_blocking


🎈 Thanks for your help improving the project!
No contribution is too small and all contributions are valued, feel free to open Issues and submit Pull Requests


This project is licensed under the MIT license.


Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Refinery by you, shall be licensed as MIT, without any additional
terms or conditions.

Read More

Leave a Reply

Your email address will not be published.