@@ -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 :: {
@@ -538,21 +539,37 @@ impl<'conn> MasWriter<'conn> {
538
539
Ok ( ( indices_to_restore, constraints_to_restore) )
539
540
}
540
541
542
+ #[ tracing:: instrument( skip_all, fields( indicatif. pb_show) ) ]
541
543
async fn restore_indices (
542
544
conn : & mut LockedMasDatabase < ' _ > ,
543
545
indices_to_restore : & [ IndexDescription ] ,
544
546
constraints_to_restore : & [ ConstraintDescription ] ,
545
547
) -> Result < ( ) , Error > {
548
+ let span = Span :: current ( ) ;
549
+ // TODO this style is a quick workaround for showing the message, but
550
+ // might not be optimal for other purposes
551
+ span. pb_set_style (
552
+ & ProgressStyle :: with_template (
553
+ "[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}" ,
554
+ )
555
+ . unwrap ( ) ,
556
+ ) ;
557
+ span. pb_set_length ( ( indices_to_restore. len ( ) + constraints_to_restore. len ( ) ) as u64 ) ;
558
+
546
559
// First restore all indices. The order is not important as far as I know.
547
560
// However the indices are needed before constraints.
548
561
for index in indices_to_restore. iter ( ) . rev ( ) {
562
+ span. pb_set_message ( & format ! ( "building index: {}" , & index. name) ) ;
549
563
constraint_pausing:: restore_index ( conn. as_mut ( ) , index) . await ?;
564
+ span. pb_inc ( 1 ) ;
550
565
}
551
566
// Then restore all constraints.
552
567
// The order here is the reverse of drop order, since some constraints may rely
553
568
// on other constraints to work.
554
569
for constraint in constraints_to_restore. iter ( ) . rev ( ) {
570
+ span. pb_set_message ( & format ! ( "building constraint: {}" , & constraint. name) ) ;
555
571
constraint_pausing:: restore_constraint ( conn. as_mut ( ) , constraint) . await ?;
572
+ span. pb_inc ( 1 ) ;
556
573
}
557
574
Ok ( ( ) )
558
575
}
0 commit comments