All Projects → rust-db → Refinery

rust-db / Refinery

Licence: mit
Powerful SQL migration toolkit for Rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Refinery

php-database-migration
Database Migration tool for PHP
Stars: ✭ 86 (-85.74%)
Mutual labels:  database-migrations
poco restful webservice
A RESTful API using Poco C++ Libraries.
Stars: ✭ 54 (-91.04%)
Mutual labels:  database-migrations
Compalex
Lightweight script to compare two database
Stars: ✭ 318 (-47.26%)
Mutual labels:  database-migrations
liquibase-impala
Liquibase extension to add Impala Database support
Stars: ✭ 23 (-96.19%)
Mutual labels:  database-migrations
mongo-migrate
Versioned migrations for MongoDB.
Stars: ✭ 79 (-86.9%)
Mutual labels:  database-migrations
sync-db
Utility to synchronize relational database objects across databases.
Stars: ✭ 15 (-97.51%)
Mutual labels:  database-migrations
java-migrations
📃 Laravel inspired DBS-independent Database Migrations for Java 8 (work in progress)
Stars: ✭ 21 (-96.52%)
Mutual labels:  database-migrations
Migrate Mongo
A database migration tool for MongoDB in Node
Stars: ✭ 481 (-20.23%)
Mutual labels:  database-migrations
cl-migratum
Database Schema Migration System for Common Lisp
Stars: ✭ 29 (-95.19%)
Mutual labels:  database-migrations
Erd
A Rails engine for drawing your app's ER diagram
Stars: ✭ 296 (-50.91%)
Mutual labels:  database-migrations
lein-flyway
Leiningen Plugin for Flyway
Stars: ✭ 25 (-95.85%)
Mutual labels:  database-migrations
framework
A stylish PHP application framework crafted using Slim, Twig, Eloquent and Sentinel designed to get you from clone to production in a matter of minutes.
Stars: ✭ 56 (-90.71%)
Mutual labels:  database-migrations
Yii2 Migration
Yii 2 Migration Creator And Updater
Stars: ✭ 262 (-56.55%)
Mutual labels:  database-migrations
migrant lib
Embeddable migration management
Stars: ✭ 22 (-96.35%)
Mutual labels:  database-migrations
Shmig
Database migration tool written in BASH.
Stars: ✭ 408 (-32.34%)
Mutual labels:  database-migrations
wildebeest
Database migration for Sequelize.
Stars: ✭ 13 (-97.84%)
Mutual labels:  database-migrations
carry
Python ETL(Extract-Transform-Load) tool / Data migration tool
Stars: ✭ 115 (-80.93%)
Mutual labels:  database-migrations
Tenanti
[Package] Multi-tenant Database Schema Manager for Laravel
Stars: ✭ 525 (-12.94%)
Mutual labels:  database-migrations
Phinx
PHP Database Migrations for Everyone
Stars: ✭ 4,245 (+603.98%)
Mutual labels:  database-migrations
Pg chameleon
MySQL to PostgreSQL replica system
Stars: ✭ 274 (-54.56%)
Mutual labels:  database-migrations

refinery Logo

Powerful SQL migration toolkit for Rust.

Crates.io docs.rs 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, tokio-postgres , mysql, mysql_async and rusqlite are supported.
If you are using a driver that is not yet supported, namely SQLx you can run migrations providing a Config instead of the connection type, as Config impl's Migrate. You will still need to provide the postgres/mysql/rusqlite driver as a feature for Runner::run and tokio-postgres/mysql_async for Runner::run_async.
refinery works best with Barrel but you can also have your migrations in .sql files or use any other Rust crate for schema generation.

Usage

  • Add refinery to your Cargo.toml dependencies with the selected driver as feature eg: refinery = { version = "0.3", features = ["rusqlite"]}
  • Migrations can be defined in .sql files or Rust modules that must have a function called migration that returns a String.
  • Migrations can be strictly versioned by prefixing the file with V or not strictly versioned by prefixing the file with U.
  • Migrations, both .sql files and Rust modules must be named in the format [U|V]{1}__{2}.sql or [U|V]{1}__{2}.rs, where {1} represents the migration version and {2} the name.
  • Migrations can be run either by embedding them in your Rust code with embed_migrations and include_migration_mods macros, or via refinery_cli.

Example

use rusqlite::Connection;

mod embedded {
    use refinery::embed_migrations;
    embed_migrations!("./tests/sql_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.

Unversioned VS Versioned migrations

Depending on how your project / team has been structured will define whether you want to use Versioned migrations V{1}__{2}.[sql|rs] or Unversioned migrations U{1}__{2}.[sql|rs]. If all migrations are created synchronously and are deployed synchronously you won't run into any problems using Versioned migrations. This is because you can be sure the next migration being run is always going to have a version number greater than the previous.

With Unversioned migrations there is more flexibility in the order that the migrations can be created and deployed. If developer 1 creates a PR with a migration today U11__update_cars_table.sql, but it is reviewed for a week. Meanwhile developer 2 creates a PR with migration U12__create_model_tags.sql that is much simpler and gets merged and deployed immediately. This would stop developer 1's migration from ever running if you were using Versioned migrations because the next migration would need to be > 12.

Implementation details

refinery works by creating a table that keeps all the applied migrations' versions and their metadata. When you run the migrations Runner, refinery compares the applied migrations with the the ones to be applied, checking for divergent and missing and executing unapplied migrations.
By default, refinery runs each migration in a single transaction. Alternatively, you can also configure refinery to wrap the entire execution of all migrations in a single transaction by setting set_grouped to true.

Rollback

refinery's design is based on flyway and so, shares its perspective on undo/rollback migrations. To undo/rollback a migration, you have to generate a new one and write specifically what you want to undo.

Compatibility

refinery aims to support stable Rust, the previous Rust version, and nightly.

Async

Starting with version 0.2 refinery supports tokio-postgres and mysql_async. To migrate async you have to call Runner's run_async. There are plans to support Tiberius when futures 0.3 support stabilizes. For Rusqlite, the best way to run migrations in an async context is to run them inside tokio's spawn_blocking for example.

Contributing

🎈 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.

License

This project is licensed under the MIT license.

Contribution

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].