@@ -36,7 +36,6 @@ pub fn migrate<T: Transaction>(
36
36
}
37
37
}
38
38
39
- log:: info!( "applying migration: {}" , migration) ;
40
39
migration. set_applied ( ) ;
41
40
let insert_migration = insert_migration_query ( & migration, migration_table_name) ;
42
41
let migration_sql = migration. sql ( ) . expect ( "sql must be Some!" ) . to_string ( ) ;
@@ -51,31 +50,46 @@ pub fn migrate<T: Transaction>(
51
50
52
51
match ( target, batched) {
53
52
( 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. " ) ;
55
54
}
56
55
( Target :: Latest | Target :: Version ( _) , true ) => {
57
56
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 ( )
60
59
) ;
61
60
}
62
61
( Target :: Latest | Target :: Version ( _) , false ) => {
63
62
log:: info!(
64
- "preparing to apply {} migrations: {:#?} " ,
63
+ "going to apply {} migrations in multiple transactions. " ,
65
64
applied_migrations. len( ) ,
66
- applied_migrations. iter( ) . map( ToString :: to_string)
67
65
) ;
68
66
}
69
67
} ;
70
68
71
69
let refs: Vec < & str > = migration_batch. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
72
70
73
71
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}" ) ;
74
78
transaction
75
79
. execute ( refs. as_ref ( ) )
76
80
. migration_err ( "error applying migrations" , None ) ?;
77
81
} else {
78
82
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
+ }
79
93
transaction
80
94
. execute ( & [ update] )
81
95
. migration_err ( "error applying update" , Some ( & applied_migrations[ 0 ..i / 2 ] ) ) ?;
0 commit comments