Crates.io | flyway |
lib.rs | flyway |
version | 0.3.1 |
source | src |
created_at | 2023-03-29 01:57:04.362661 |
updated_at | 2023-12-24 17:07:05.932643 |
description | Flyway-rs project, Database change control,similar to flyway in Java |
homepage | https://github.com/tdcare/flyway-rs |
repository | https://github.com/tdcare/flyway-rs |
max_upload_size | |
id | 823601 |
size | 20,117 |
flyway
is a collection of Rust crates for loading and executing database
migrations.
It supposed to be an alternative to refinery
and was created because refinery
is pretty closed when it comes to database drivers. Basically
it is not possible to create database driver crates for refinery
without creating either a
fork or including the driver inside the refinery
crate. The reason is that the
refinery::Migration::applied(...)
method is not public, which prevents other crates from implementing
the refinery::AsyncMigrate
trait and reading this issue
it seems the authors are not motivated to change this behaviour.
flyway
consists of multiple crates:
flyway
: The main crate. Contains the migration runner and re-exports necessary
macros and structs from other flyway crates.flyway-rbatis
: A driver for executing DB migrations via the
Rbatis database library.flyway-codegen
: Contains the migrations
attribute macroflyway-sql-changelog
: Contains the ChangelogFile
struct that can load
SQL files and split them into separate, annotated statements
via a SqlStatementIterator
.This crate has some known (and probably some unknown) limitations and stability issues:
iter()
implementation for ChangelogFile
is not conforming to the Rust standards
yet.flyway-rbatis
uses one set of queries for all database drivers supported
by Rbatis. As far as i can tell from e.g. refinery
, some database systems (specifically MSSQL)
support or even need a different syntax for state management.All the crates in this project are libraries. The included tests can be started via:
~$ cd flyway
~/flyway$ cargo test
To use the crates inside your project, the following steps should be taken:
Cargo.toml
(get available versions
from crates.io):# Add the flyway dependency
[dependency.flyway]
version = "<version>"
# Add the flyway-rbatis dependency in order to run migrations via Rbatis. At the time
# of writing, this is the only supported database driver.
[dependency.flyway-rbatis]
version = "<version>"
# Add Rbatis dependencies ...
main.rs
:use flyway::{MigrationExecutor, MigrationState, MigrationStateManager, MigrationStore, migrations, MigrationRunner};
use flyway_rbatis::RbatisMigrationDriver;
use rbatis::Rbatis;
// Load migrations (SQL files) from `examples/migrations` and make them available via
// `Migrations::changelog()`. The generated class can be used for `MigrationRunner::migrate(...)`.
#[migrations("examples/migrations")]
pub struct Migrations {
}
async fn run(rbatis: Arc<Rbatis>) -> Result<()> {
let migration_driver = Arc::new(RbatisMigrationDriver::new(rbatis.clone(), None));
let migration_runner = MigrationRunner::new(
Migrations {},
migration_driver.clone(),
migration_driver.clone()
);
migration_runner.migrate().await?;
}
// Add main method that creates an `Rbatis` instance and calls the `run(...)` method.
// ...
The project is licensed under the MIT.