1 Star 0 Fork 0

提灯医疗 / flyway-rs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

flyway-rs copy from db-up

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:

  • Top-level 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.
  • Other crates:
    • flyway-codegen: Contains the migrations attribute macro
    • flyway-sql-changelog: Contains the ChangelogFile struct that can load SQL files and split them into separate, annotated statements via a SqlStatementIterator.

Status

This crate has some known (and probably some unknown) limitations and stability issues:

  • The transaction management is not finished yet. At the moment, only a "one transaction per changelog" mode is implemented, but no "one transaction for all changes" mode. I'm not sure if anyone will need the latter, but it i plan to implement it at some point.
  • The "last successful version" is not set correctly at many places, especially when producing errors.
  • The iter() implementation for ChangelogFile is not conforming to the Rust standards yet.
  • For now, there is only an Rbatis driver implementation available.
  • The Rbatis driver in 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.
  • More examples should be added.
  • More tests should be added.

Usage

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:

  1. Include the necessary crates in your 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 ...
  1. E.g in your 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.
// ...

License

The project is licensed under the MIT.

MIT License Copyright (c) 2023 提灯医疗 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

功能与Java版的 Flyway 类似 展开 收起
Rust
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Rust
1
https://gitee.com/tdcare/flyway-rs.git
git@gitee.com:tdcare/flyway-rs.git
tdcare
flyway-rs
flyway-rs
main

搜索帮助