Skip to content

Commit

Permalink
Dynamic embedded migrations (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
quasi-coherent authored Sep 30, 2024
1 parent e160e99 commit 64f456a
Show file tree
Hide file tree
Showing 24 changed files with 557 additions and 296 deletions.
2 changes: 1 addition & 1 deletion refinery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ for more examples refer to the [examples](https://github.com/rust-db/refinery/tr
pub use refinery_core::config;
pub use refinery_core::{error, load_sql_migrations, Error, Migration, Report, Runner, Target};
#[doc(hidden)]
pub use refinery_core::{AsyncMigrate, Migrate};
pub use refinery_core::{AsyncExecutor, AsyncMigrate, Executor, Migrate};
pub use refinery_macros::embed_migrations;
16 changes: 14 additions & 2 deletions refinery/tests/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,37 @@ mod mysql {
fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");

let migration1 =
Migration::unapplied("V1__initial.rs", &migrations::V1__initial::migration()).unwrap();
let migration1 = Migration::unapplied(
"V1__initial.rs",
None,
&migrations::V1__initial::migration(),
)
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_and_motos_table.sql",
None,
include_str!("./migrations/V1-2/V2__add_cars_and_motos_table.sql"),
)
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
None,
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();

let migration4 = Migration::unapplied(
"V4__add_year_to_motos_table.rs",
None,
&migrations::V4__add_year_to_motos_table::migration(),
)
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -472,6 +480,7 @@ mod mysql {

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -508,6 +517,7 @@ mod mysql {

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -545,6 +555,7 @@ mod mysql {

let migration1 = Migration::unapplied(
"V1__initial",
None,
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -557,6 +568,7 @@ mod mysql {

let migration2 = Migration::unapplied(
"V2__add_cars_table",
None,
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
16 changes: 14 additions & 2 deletions refinery/tests/mysql_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,37 @@ mod mysql_async {
fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");

let migration1 =
Migration::unapplied("V1__initial.rs", &migrations::V1__initial::migration()).unwrap();
let migration1 = Migration::unapplied(
"V1__initial.rs",
None,
&migrations::V1__initial::migration(),
)
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_and_motos_table.sql",
None,
include_str!("./migrations/V1-2/V2__add_cars_and_motos_table.sql"),
)
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
None,
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();

let migration4 = Migration::unapplied(
"V4__add_year_to_motos_table.rs",
None,
&migrations::V4__add_year_to_motos_table::migration(),
)
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -482,6 +490,7 @@ mod mysql_async {

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -527,6 +536,7 @@ mod mysql_async {

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -568,6 +578,7 @@ mod mysql_async {

let migration1 = Migration::unapplied(
"V1__initial",
None,
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -580,6 +591,7 @@ mod mysql_async {

let migration2 = Migration::unapplied(
"V2__add_cars_table",
None,
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
16 changes: 14 additions & 2 deletions refinery/tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,37 @@ mod postgres {
fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");

let migration1 =
Migration::unapplied("V1__initial.rs", &migrations::V1__initial::migration()).unwrap();
let migration1 = Migration::unapplied(
"V1__initial.rs",
None,
&migrations::V1__initial::migration(),
)
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_and_motos_table.sql",
None,
include_str!("./migrations/V1-2/V2__add_cars_and_motos_table.sql"),
)
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
None,
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();

let migration4 = Migration::unapplied(
"V4__add_year_to_motos_table.rs",
None,
&migrations::V4__add_year_to_motos_table::migration(),
)
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -446,6 +454,7 @@ mod postgres {

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -479,6 +488,7 @@ mod postgres {

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -513,6 +523,7 @@ mod postgres {

let migration1 = Migration::unapplied(
"V1__initial",
None,
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -525,6 +536,7 @@ mod postgres {

let migration2 = Migration::unapplied(
"V2__add_cars_table",
None,
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
16 changes: 14 additions & 2 deletions refinery/tests/rusqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,37 @@ mod rusqlite {
fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");

let migration1 =
Migration::unapplied("V1__initial.rs", &migrations::V1__initial::migration()).unwrap();
let migration1 = Migration::unapplied(
"V1__initial.rs",
None,
&migrations::V1__initial::migration(),
)
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_and_motos_table.sql",
None,
include_str!("./migrations/V1-2/V2__add_cars_and_motos_table.sql"),
)
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
None,
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();

let migration4 = Migration::unapplied(
"V4__add_year_to_motos_table.rs",
None,
&migrations::V4__add_year_to_motos_table::migration(),
)
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -572,6 +580,7 @@ mod rusqlite {

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -603,6 +612,7 @@ mod rusqlite {

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -635,6 +645,7 @@ mod rusqlite {

let migration1 = Migration::unapplied(
"V1__initial",
None,
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -647,6 +658,7 @@ mod rusqlite {

let migration2 = Migration::unapplied(
"V2__add_cars_table",
None,
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
16 changes: 14 additions & 2 deletions refinery/tests/tiberius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,37 @@ mod tiberius {
fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");

let migration1 =
Migration::unapplied("V1__initial.rs", &migrations::V1__initial::migration()).unwrap();
let migration1 = Migration::unapplied(
"V1__initial.rs",
None,
&migrations::V1__initial::migration(),
)
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_and_motos_table.sql",
None,
include_str!("./migrations/V1-2/V2__add_cars_and_motos_table.sql"),
)
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
None,
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();

let migration4 = Migration::unapplied(
"V4__add_year_to_motos_table.rs",
None,
&migrations::V4__add_year_to_motos_table::migration(),
)
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -127,6 +135,7 @@ mod tiberius {

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -178,6 +187,7 @@ mod tiberius {

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
None,
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -230,6 +240,7 @@ mod tiberius {

let migration1 = Migration::unapplied(
"V1__initial",
None,
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -242,6 +253,7 @@ mod tiberius {

let migration2 = Migration::unapplied(
"V2__add_cars_table",
None,
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
Loading

0 comments on commit 64f456a

Please sign in to comment.