diff --git a/.circleci/config.yml b/.circleci/config.yml index 61540b03..7fec0bca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,6 +49,7 @@ jobs: - run: rustup component add clippy - run: rustup component add rustfmt - run: cargo fmt --all -- --check + - run: cd refinery_core && cargo test - run: cd refinery && cargo build --all-features - run: cd refinery_macros && cargo clippy - run: cd refinery_cli && cargo clippy diff --git a/.travis.yml b/.travis.yml index 8f02ce79..c414c7e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ jobs: - stage: windows nightly rust: nightly script: - - cd refinery && cargo test --lib + - cd refinery_core && cargo test --lib diff --git a/refinery_core/Cargo.toml b/refinery_core/Cargo.toml index 01538a31..b25fc1f1 100644 --- a/refinery_core/Cargo.toml +++ b/refinery_core/Cargo.toml @@ -33,5 +33,8 @@ mysql_async = { version = "0.21", optional = true } tokio = { version = "0.2", features = ["full"], optional = true } +[dev-dependencies] +tempfile = "3.1.0" + [package.metadata.docs.rs] all-features = true diff --git a/refinery_core/src/lib.rs b/refinery_core/src/lib.rs index ea0b128c..77090606 100644 --- a/refinery_core/src/lib.rs +++ b/refinery_core/src/lib.rs @@ -1,37 +1,3 @@ -/*! -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`](https://crates.io/crates/postgres), [`Rusqlite`](https://crates.io/crates/rusqlite), and [`Mysql`](https://crates.io/crates/mysql) are supported.\ - -`refinery` works best with [`Barrel`](https://crates.io/crates/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 a [`std::string::String`] -- Migrations, both .sql files and Rust modules must be named in the format `V{1}__{2}.rs ` where `{1}` represents the migration version and `{2}` the name. -- Migrations can be run either by embedding them on your Rust code with [`embed_migrations!`] and [`include_migration_mods!`] macros, or via `refinery_cli`. - -[`embed_migrations!`]: macro.embed_migrations.html -[`include_migration_mods!`]: macro.include_migration_mods.html - -### Example -```rust,no_run -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](https://github.com/rust-db/refinery/tree/master/examples) -*/ - pub mod config; mod drivers; mod error; diff --git a/refinery_core/src/traits/mod.rs b/refinery_core/src/traits/mod.rs index 4fc68162..467af406 100644 --- a/refinery_core/src/traits/mod.rs +++ b/refinery_core/src/traits/mod.rs @@ -92,19 +92,23 @@ mod tests { fn get_migrations() -> Vec { let migration1 = Migration::from_filename( "V1__initial.sql", - include_str!("../../tests/sql_migrations/V1-2/V1__initial.sql"), + include_str!("../../../refinery/tests/sql_migrations/V1-2/V1__initial.sql"), ) .unwrap(); let migration2 = Migration::from_filename( "V2__add_cars_and_motos_table.sql", - include_str!("../../tests/sql_migrations/V1-2/V2__add_cars_and_motos_table.sql"), + include_str!( + "../../../refinery/tests/sql_migrations/V1-2/V2__add_cars_and_motos_table.sql" + ), ) .unwrap(); let migration3 = Migration::from_filename( "V3__add_brand_to_cars_table", - include_str!("../../tests/sql_migrations/V3/V3__add_brand_to_cars_table.sql"), + include_str!( + "../../../refinery/tests/sql_migrations/V3/V3__add_brand_to_cars_table.sql" + ), ) .unwrap(); diff --git a/refinery_core/src/util.rs b/refinery_core/src/util.rs index d999f333..3cfd1baa 100644 --- a/refinery_core/src/util.rs +++ b/refinery_core/src/util.rs @@ -70,8 +70,8 @@ mod tests { .unwrap() .collect(); mods.sort(); - assert_eq!(sql1, mods[0]); - assert_eq!(sql2, mods[1]); + assert_eq!(sql1.canonicalize().unwrap(), mods[0]); + assert_eq!(sql2.canonicalize().unwrap(), mods[1]); } #[test] @@ -102,8 +102,8 @@ mod tests { .unwrap() .collect(); mods.sort(); - assert_eq!(sql1, mods[0]); - assert_eq!(sql2, mods[1]); + assert_eq!(sql1.canonicalize().unwrap(), mods[0]); + assert_eq!(sql2.canonicalize().unwrap(), mods[1]); } #[test]