Skip to content

Commit

Permalink
Introduce Inquire crate in rust-pgdatadiff-client
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlospt committed Mar 15, 2024
1 parent 8d5edaa commit c1957df
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 34 deletions.
1 change: 1 addition & 0 deletions rust-pgdatadiff-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ clap = { version = "4.5.2", features = ["derive"] }
tokio = "1.36.0"
env_logger = "0.11.3"
rust-pgdatadiff = { version = "0.1.2", path = ".." }
inquire = "0.7.1"
125 changes: 91 additions & 34 deletions rust-pgdatadiff-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use inquire::{Confirm, Text};
use rust_pgdatadiff::diff::diff_ops::Differ;
use rust_pgdatadiff::diff::diff_payload::DiffPayload;

Expand Down Expand Up @@ -51,38 +52,94 @@ enum Commands {
async fn main() -> Result<()> {
env_logger::init();

let cli = Cli::parse();
match &cli.command {
Commands::Version => {
println!("Version: {}", env!("CARGO_PKG_VERSION"));
Ok(())
}
Commands::Diff {
first_db,
second_db,
only_tables,
only_sequences,
only_count,
chunk_size,
max_connections,
include_tables,
exclude_tables,
schema_name,
} => {
let payload = DiffPayload::new(
first_db.clone(),
second_db.clone(),
*only_tables,
*only_sequences,
*only_count,
*chunk_size,
*max_connections,
include_tables.to_vec(),
exclude_tables.to_vec(),
schema_name.clone(),
);
let _ = Differ::diff_dbs(payload).await;
Ok(())
}
}
// let cli = Cli::parse();
// match &cli.command {
// Commands::Version => {
// println!("Version: {}", env!("CARGO_PKG_VERSION"));
// Ok(())
// }
// Commands::Diff {
// first_db,
// second_db,
// only_tables,
// only_sequences,
// only_count,
// chunk_size,
// max_connections,
// include_tables,
// exclude_tables,
// schema_name,
// } => {
// let payload = DiffPayload::new(
// first_db.clone(),
// second_db.clone(),
// *only_tables,
// *only_sequences,
// *only_count,
// *chunk_size,
// *max_connections,
// include_tables.to_vec(),
// exclude_tables.to_vec(),
// schema_name.clone(),
// );
// let _ = Differ::diff_dbs(payload).await;
// Ok(())
// }
// }

let first_db = Text::new("First DB")
.with_default("postgres://postgres:postgres@localhost:5438/example")
.with_help_message("Enter the first database connection string")
.prompt()?;
let second_db = Text::new("Second DB")
.with_default("postgres://postgres:postgres@localhost:5439/example")
.with_help_message("Enter the first database connection string")
.prompt()?;
let only_tables = Confirm::new("Do you want to only compare tables?")
.with_default(false)
.with_help_message("By confirming this option, you will only compare tables")
.prompt()?;
let only_sequences = Confirm::new("Do you want to only compare sequences?")
.with_default(false)
.with_help_message("By confirming this option, you will only compare sequences")
.prompt()?;
let only_count = Confirm::new("Do you want to only count rows of tables?")
.with_default(false)
.with_help_message("By confirming this option, you will only row counts of tables")
.prompt()?;
let chunk_size = Text::new("Number of rows to compare (in batch)")
.with_default("10000")
.with_help_message("Enter the chunk size when comparing data")
.prompt()?;
let max_connections = Text::new("Number of DB connections to utilize")
.with_default("100")
.with_help_message("Enter the max connections for Postgres pool")
.prompt()?;
let include_tables = Text::new("Tables to include in the comparison")
.with_default("")
.with_help_message("Enter the tables to include in the comparison (comma separated)")
.prompt()?;
let exclude_tables = Text::new("Tables to exclude from the comparison")
.with_default("")
.with_help_message("Enter the tables to exclude from the comparison (comma separated)")
.prompt()?;
let schema_name = Text::new("DB schema name to compare")
.with_default("public")
.with_help_message("Enter the DB schema name to perform the comparison on")
.prompt()?;

let payload = DiffPayload::new(
first_db,
second_db,
only_tables,
only_sequences,
only_count,
chunk_size.parse::<i64>().unwrap(),
max_connections.parse::<i64>().unwrap(),
include_tables.trim().split_whitespace().into_iter().collect(),
exclude_tables.trim().split_whitespace().into_iter().collect(),
schema_name,
);
let _ = Differ::diff_dbs(payload).await;
Ok(())
}

0 comments on commit c1957df

Please sign in to comment.