44//! transactions, and will likely fail if used on a populated database.
55
66use chrono:: { DateTime , Utc } ;
7+ use clap:: { builder:: PossibleValuesParser , ArgAction } ;
78use database:: pool:: { postgres, sqlite, ConnectionManager } ;
89use futures:: StreamExt ;
910use rusqlite:: params;
@@ -462,37 +463,42 @@ async fn main() -> anyhow::Result<()> {
462463
463464 let table_names: Vec < _ > = tables. iter ( ) . map ( |table| table. name ( ) ) . collect ( ) ;
464465
465- let matches = clap:: App :: new ( "postgres-to-sqlite" )
466+ let matches = clap:: Command :: new ( "postgres-to-sqlite" )
466467 . about ( "Exports a rustc-perf Postgres database to a SQLite database" )
467468 . version ( clap:: crate_version!( ) )
468469 . arg (
469470 clap:: Arg :: new ( "exclude-tables" )
471+ . action ( ArgAction :: Set )
470472 . long ( "exclude-tables" )
471- . takes_value ( true )
472473 . value_name ( "TABLES" )
473- . possible_values ( & table_names)
474- . use_delimiter ( true )
474+ . value_parser ( PossibleValuesParser :: new ( table_names) )
475+ . takes_value ( true )
476+ . use_value_delimiter ( true )
475477 . help ( "Exclude given tables (as foreign key constraints allow)" ) ,
476478 )
477479 . arg (
478480 clap:: Arg :: new ( "no-self-profile" )
481+ . action ( ArgAction :: SetTrue )
479482 . long ( "no-self-profile" )
480483 . help ( "Exclude some potentially large self-profile tables (additive with --exclude-tables)" ) ,
481484 )
482485 . arg (
483486 clap:: Arg :: new ( "since-weeks-ago" )
487+ . action ( ArgAction :: Set )
484488 . long ( "since-weeks-ago" )
485489 . takes_value ( true )
486490 . value_name ( "WEEKS" )
487491 . help ( "Exclude data associated with artifacts whose date value precedes <WEEKS> weeks ago" ) ,
488492 )
489493 . arg (
490494 clap:: Arg :: new ( "fast-unsafe" )
495+ . action ( ArgAction :: SetTrue )
491496 . long ( "fast-unsafe" )
492497 . help ( "Enable faster execution at the risk of corrupting SQLite database in the event of a crash" ) ,
493498 )
494499 . arg (
495500 clap:: Arg :: new ( "postgres-db" )
501+ . action ( ArgAction :: Set )
496502 . required ( true )
497503 . value_name ( "POSTGRES_DB" )
498504 . help (
@@ -502,31 +508,29 @@ async fn main() -> anyhow::Result<()> {
502508 )
503509 . arg (
504510 clap:: Arg :: new ( "sqlite-db" )
511+ . action ( ArgAction :: Set )
505512 . required ( true )
506513 . value_name ( "SQLITE_DB" )
507514 . help ( "SQLite database file" ) ,
508515 )
509516 . get_matches ( ) ;
510517
511- let postgres = matches. value_of ( "postgres-db" ) . unwrap ( ) ;
512- let sqlite = matches. value_of ( "sqlite-db" ) . unwrap ( ) ;
518+ let postgres = matches. get_one :: < String > ( "postgres-db" ) . unwrap ( ) ;
519+ let sqlite = matches. get_one :: < String > ( "sqlite-db" ) . unwrap ( ) ;
513520
514521 let mut exclude_tables: std:: collections:: HashSet < _ > = matches
515- . values_of ( "exclude-tables" )
522+ . get_many :: < String > ( "exclude-tables" )
516523 . unwrap_or_default ( )
524+ . cloned ( )
517525 . collect ( ) ;
518526
519- if matches. is_present ( "no-self-profile" ) {
520- exclude_tables. insert ( SelfProfileQuerySeries . name ( ) ) ;
521- exclude_tables. insert ( SelfProfileQuery . name ( ) ) ;
527+ if matches. get_flag ( "no-self-profile" ) {
528+ exclude_tables. insert ( SelfProfileQuerySeries . name ( ) . to_owned ( ) ) ;
529+ exclude_tables. insert ( SelfProfileQuery . name ( ) . to_owned ( ) ) ;
522530 // `RawSelfProfile` is intentionally kept.
523531 }
524532
525- let since_weeks_ago = match matches. value_of_t ( "since-weeks-ago" ) {
526- Ok ( weeks) => Some ( weeks) ,
527- Err ( err) if err. kind == clap:: ErrorKind :: ArgumentNotFound => None ,
528- Err ( err) => err. exit ( ) ,
529- } ;
533+ let since_weeks_ago = matches. get_one :: < u32 > ( "since-weeks-ago" ) . copied ( ) ;
530534
531535 let mut postgres: tokio_postgres:: Client =
532536 postgres:: Postgres :: new ( postgres. into ( ) ) . open ( ) . await . into ( ) ;
@@ -537,7 +541,7 @@ async fn main() -> anyhow::Result<()> {
537541 . into_inner ( )
538542 . unwrap ( ) ;
539543
540- if matches. is_present ( "fast-unsafe" ) {
544+ if matches. get_flag ( "fast-unsafe" ) {
541545 sqlite. pragma_update ( None , "journal_mode" , & "OFF" ) . unwrap ( ) ;
542546 sqlite. pragma_update ( None , "synchronous" , & "OFF" ) . unwrap ( ) ;
543547 }
@@ -558,7 +562,7 @@ async fn main() -> anyhow::Result<()> {
558562 let sqlite_tx = sqlite. transaction ( ) . unwrap ( ) ;
559563
560564 for & table in tables {
561- if !exclude_tables. contains ( & table. name ( ) ) {
565+ if !exclude_tables. contains ( table. name ( ) ) {
562566 copy ( table, & postgres_tx, & sqlite_tx, since_weeks_ago) . await ;
563567 }
564568 }
0 commit comments