Expand description
Powerful SQL migration toolkit for Rust.
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.
§Usage
- Migrations can be defined in .sql files or Rust modules that must have a function called
migration()that returns astd::string::String - Migrations, both .sql files and Rust modules must be named in the format
V{1}__{2}.rswhere{1}represents the migration version and{2}the name. - Migrations can be run either by embedding them on your Rust code with
embed_migrations!macro, or viarefinery_cli.
§Example
ⓘ
use rusqlite::Connection;
mod embedded {
use refinery::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
Modules§
Macros§
- embed_
migrations - Interpret Rust or SQL migrations and inserts a function called runner that when called returns a
Runnerinstance with the collected migration modules.
Structs§
- Error
- An Error occurred during a migration cycle
- Migration
- Represents a schema migration to be run on the database,
this struct is used by the
embed_migrations!macro to gather migration files and shouldn’t be needed by the user - Report
- Struct that represents the report of the migration cycle,
a
Reportinstance is returned by theRunner::runandRunner::run_asyncmethods viaResult<Report, Error>, on case of anErrorduring a migration, you can access theReportwithError.report - Runner
- Struct that represents the entrypoint to run the migrations,
an instance of this struct is returned by the
embed_migrations!macro.Runnershould not need to be instantiated manually
Enums§
- Target
- An enum set that represents the target version up to which refinery should migrate, it is used by Runner
Functions§
- load_
sql_ migrations - Loads SQL migrations from a path. This enables dynamic migration discovery, as opposed to embedding. The resulting collection is ordered by version.