@@ -22,7 +22,8 @@ use sqlx::{Executor, PgConnection, query, query_as};
22
22
use thiserror:: Error ;
23
23
use thiserror_ext:: { Construct , ContextInto } ;
24
24
use tokio:: sync:: mpsc:: { self , Receiver , Sender } ;
25
- use tracing:: { Level , error, info, warn} ;
25
+ use tracing:: { Level , Span , error, info, warn} ;
26
+ use tracing_indicatif:: { span_ext:: IndicatifSpanExt , style:: ProgressStyle } ;
26
27
use uuid:: Uuid ;
27
28
28
29
use self :: {
@@ -542,21 +543,37 @@ impl MasWriter {
542
543
Ok ( ( indices_to_restore, constraints_to_restore) )
543
544
}
544
545
546
+ #[ tracing:: instrument( skip_all, fields( indicatif. pb_show) ) ]
545
547
async fn restore_indices (
546
548
conn : & mut LockedMasDatabase ,
547
549
indices_to_restore : & [ IndexDescription ] ,
548
550
constraints_to_restore : & [ ConstraintDescription ] ,
549
551
) -> Result < ( ) , Error > {
552
+ let span = Span :: current ( ) ;
553
+ // TODO this style is a quick workaround for showing the message, but
554
+ // might not be optimal for other purposes
555
+ span. pb_set_style (
556
+ & ProgressStyle :: with_template (
557
+ "[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}" ,
558
+ )
559
+ . unwrap ( ) ,
560
+ ) ;
561
+ span. pb_set_length ( ( indices_to_restore. len ( ) + constraints_to_restore. len ( ) ) as u64 ) ;
562
+
550
563
// First restore all indices. The order is not important as far as I know.
551
564
// However the indices are needed before constraints.
552
565
for index in indices_to_restore. iter ( ) . rev ( ) {
566
+ span. pb_set_message ( & format ! ( "building index: {}" , & index. name) ) ;
553
567
constraint_pausing:: restore_index ( conn. as_mut ( ) , index) . await ?;
568
+ span. pb_inc ( 1 ) ;
554
569
}
555
570
// Then restore all constraints.
556
571
// The order here is the reverse of drop order, since some constraints may rely
557
572
// on other constraints to work.
558
573
for constraint in constraints_to_restore. iter ( ) . rev ( ) {
574
+ span. pb_set_message ( & format ! ( "building constraint: {}" , & constraint. name) ) ;
559
575
constraint_pausing:: restore_constraint ( conn. as_mut ( ) , constraint) . await ?;
576
+ span. pb_inc ( 1 ) ;
560
577
}
561
578
Ok ( ( ) )
562
579
}
0 commit comments