diff --git a/refinery/tests/mysql.rs b/refinery/tests/mysql.rs index a9c487b..4394473 100644 --- a/refinery/tests/mysql.rs +++ b/refinery/tests/mysql.rs @@ -776,8 +776,10 @@ mod mysql { ]) .unwrap() .assert() - .stdout(contains("applying migration: V2__add_cars_and_motos_table")) - .stdout(contains("applying migration: V3__add_brand_to_cars_table")); + .stdout(contains( + "applying migration:\tV2__add_cars_and_motos_table", + )) + .stdout(contains("applying migration:\tV3__add_brand_to_cars_table")); }) } } diff --git a/refinery/tests/postgres.rs b/refinery/tests/postgres.rs index ec10a2c..1a1de54 100644 --- a/refinery/tests/postgres.rs +++ b/refinery/tests/postgres.rs @@ -724,8 +724,10 @@ mod postgres { ]) .unwrap() .assert() - .stdout(contains("applying migration: V2__add_cars_and_motos_table")) - .stdout(contains("applying migration: V3__add_brand_to_cars_table")); + .stdout(contains( + "applying migration:\tV2__add_cars_and_motos_table", + )) + .stdout(contains("applying migration:\tV3__add_brand_to_cars_table")); }) } } diff --git a/refinery/tests/rusqlite.rs b/refinery/tests/rusqlite.rs index 258af42..f26611a 100644 --- a/refinery/tests/rusqlite.rs +++ b/refinery/tests/rusqlite.rs @@ -840,8 +840,10 @@ mod rusqlite { ]) .unwrap() .assert() - .stdout(contains("applying migration: V2__add_cars_and_motos_table")) - .stdout(contains("applying migration: V3__add_brand_to_cars_table")); + .stdout(contains( + "applying migration:\tV2__add_cars_and_motos_table", + )) + .stdout(contains("applying migration:\tV3__add_brand_to_cars_table")); }) } } diff --git a/refinery/tests/tiberius.rs b/refinery/tests/tiberius.rs index f634606..958f901 100644 --- a/refinery/tests/tiberius.rs +++ b/refinery/tests/tiberius.rs @@ -1085,8 +1085,10 @@ mod tiberius { ]) .unwrap() .assert() - .stdout(contains("applying migration: V2__add_cars_and_motos_table")) - .stdout(contains("applying migration: V3__add_brand_to_cars_table")); + .stdout(contains( + "applying migration:\tV2__add_cars_and_motos_table", + )) + .stdout(contains("applying migration:\tV3__add_brand_to_cars_table")); }) .await; } diff --git a/refinery_core/src/traits/async.rs b/refinery_core/src/traits/async.rs index fc9e4f7..7a27bc7 100644 --- a/refinery_core/src/traits/async.rs +++ b/refinery_core/src/traits/async.rs @@ -39,7 +39,7 @@ async fn migrate( } } - log::info!("applying migration: {}", migration); + log::info!("applying migration:\t{}", migration); migration.set_applied(); let update_query = insert_migration_query(&migration, migration_table_name); transaction @@ -91,9 +91,13 @@ async fn migrate_grouped( log::info!("not going to apply any migration as fake flag is enabled"); } Target::Latest | Target::Version(_) => { + let migrations_display = applied_migrations + .iter() + .map(ToString::to_string) + .collect::>() + .join("\n"); log::info!( - "going to apply batch migrations in single transaction: {:#?}", - applied_migrations.iter().map(ToString::to_string) + "going to apply batch migrations in single transaction:\n{migrations_display}" ); } }; diff --git a/refinery_core/src/traits/sync.rs b/refinery_core/src/traits/sync.rs index 23cc7a9..813a895 100644 --- a/refinery_core/src/traits/sync.rs +++ b/refinery_core/src/traits/sync.rs @@ -36,7 +36,6 @@ pub fn migrate( } } - log::info!("applying migration: {}", migration); migration.set_applied(); let insert_migration = insert_migration_query(&migration, migration_table_name); let migration_sql = migration.sql().expect("sql must be Some!").to_string(); @@ -51,19 +50,18 @@ pub fn migrate( match (target, batched) { (Target::Fake | Target::FakeVersion(_), _) => { - log::info!("not going to apply any migration as fake flag is enabled"); + log::info!("not going to apply any migration as fake flag is enabled."); } (Target::Latest | Target::Version(_), true) => { log::info!( - "going to apply batch migrations in single transaction: {:#?}", - applied_migrations.iter().map(ToString::to_string) + "going to batch apply {} migrations in single transaction.", + applied_migrations.len() ); } (Target::Latest | Target::Version(_), false) => { log::info!( - "preparing to apply {} migrations: {:#?}", + "going to apply {} migrations in multiple transactions.", applied_migrations.len(), - applied_migrations.iter().map(ToString::to_string) ); } }; @@ -71,11 +69,26 @@ pub fn migrate( let refs: Vec<&str> = migration_batch.iter().map(AsRef::as_ref).collect(); if batched { + let migrations_display = applied_migrations + .iter() + .map(ToString::to_string) + .collect::>() + .join("\n"); + log::info!("going to apply batch migrations in single transaction:\n{migrations_display}"); transaction .execute(refs.as_ref()) .migration_err("error applying migrations", None)?; } else { for (i, update) in refs.iter().enumerate() { + let applying_migration = i % 2 == 0; + + let current_migration = &applied_migrations[i / 2]; + if applying_migration { + log::info!("applying migration:\t{current_migration} ..."); + } else { + //Writing the migration state to the db + log::info!("applied migration:\t{current_migration} writing state to db."); + } transaction .execute(&[update]) .migration_err("error applying update", Some(&applied_migrations[0..i / 2]))?;