Skip to content

Commit 057ef74

Browse files
authored
fix logging output for async and sync migrate functions (#378)
1 parent 12e58d0 commit 057ef74

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

refinery_core/src/traits/async.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ async fn migrate_grouped<T: AsyncTransaction>(
9191
log::info!("not going to apply any migration as fake flag is enabled");
9292
}
9393
Target::Latest | Target::Version(_) => {
94+
let migrations_display = applied_migrations
95+
.iter()
96+
.map(ToString::to_string)
97+
.collect::<Vec<String>>()
98+
.join("\n");
9499
log::info!(
95-
"going to apply batch migrations in single transaction: {:#?}",
96-
applied_migrations.iter().map(ToString::to_string)
100+
"going to apply batch migrations in single transaction:\n{migrations_display}"
97101
);
98102
}
99103
};

refinery_core/src/traits/sync.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub fn migrate<T: Transaction>(
3636
}
3737
}
3838

39-
log::info!("applying migration: {}", migration);
4039
migration.set_applied();
4140
let insert_migration = insert_migration_query(&migration, migration_table_name);
4241
let migration_sql = migration.sql().expect("sql must be Some!").to_string();
@@ -51,31 +50,46 @@ pub fn migrate<T: Transaction>(
5150

5251
match (target, batched) {
5352
(Target::Fake | Target::FakeVersion(_), _) => {
54-
log::info!("not going to apply any migration as fake flag is enabled");
53+
log::info!("not going to apply any migration as fake flag is enabled.");
5554
}
5655
(Target::Latest | Target::Version(_), true) => {
5756
log::info!(
58-
"going to apply batch migrations in single transaction: {:#?}",
59-
applied_migrations.iter().map(ToString::to_string)
57+
"going to batch apply {} migrations in single transaction.",
58+
applied_migrations.len()
6059
);
6160
}
6261
(Target::Latest | Target::Version(_), false) => {
6362
log::info!(
64-
"preparing to apply {} migrations: {:#?}",
63+
"going to apply {} migrations in multiple transactions.",
6564
applied_migrations.len(),
66-
applied_migrations.iter().map(ToString::to_string)
6765
);
6866
}
6967
};
7068

7169
let refs: Vec<&str> = migration_batch.iter().map(AsRef::as_ref).collect();
7270

7371
if batched {
72+
let migrations_display = applied_migrations
73+
.iter()
74+
.map(ToString::to_string)
75+
.collect::<Vec<String>>()
76+
.join("\n");
77+
log::info!("going to apply batch migrations in single transaction:\n{migrations_display}");
7478
transaction
7579
.execute(refs.as_ref())
7680
.migration_err("error applying migrations", None)?;
7781
} else {
7882
for (i, update) in refs.iter().enumerate() {
83+
// first iteration is pair so we know the following even in the iteration index
84+
// marks the previous (pair) migration as completed.
85+
let applying_migration = i % 2 == 0;
86+
let current_migration = &applied_migrations[i / 2];
87+
if applying_migration {
88+
log::info!("applying migration: {current_migration} ...");
89+
} else {
90+
// Writing the migration state to the db.
91+
log::debug!("applied migration: {current_migration} writing state to db.");
92+
}
7993
transaction
8094
.execute(&[update])
8195
.migration_err("error applying update", Some(&applied_migrations[0..i / 2]))?;

0 commit comments

Comments
 (0)