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