Springtime Migrate Refinery
refinery
is powerful SQL migration toolkit for Rust, which makes creating
migrations easy. This crate integrates refinery
with the broader Springtime
Framework allowing for providing database
clients and migrations via dependency injection, which further eases creating
and applying migrations, either from files or Rust code.
Note: in addition to this crate, you need to also import springtime-di.
Features
- Automatic migration discovery
- File-based and code-based migrations
- Automatic migration application on startup for configured db clients
- All
refinery
db clients supported
Basic usage
As with refinery
, the basic usage consists of creating or embedding migrations
and providing a runner for desired database.
The following example assumes familiarity with springtime and springtime-di.
use Runner;
use application;
use ;
use ErrorPtr;
use embed_migrations;
use MigrationRunnerExecutor;
// this is all that's needed to embed sql migrations from the given folder (the default path is
// "migrations")
embed_migrations!;
// this is a migration source, which can provide migrations from code, instead of sql files
;
// register the source with dependency injection
// refinery migration runner needs a concrete DB client to run - this necessitates an abstraction
// layer; please see MigrationRunnerExecutor for details
;
// note: for the sake of simplicity, errors are unwrapped, rather than gracefully handled
async