@@ -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