use clap::{Parser, Subcommand};
mod commands;
mod output;
#[derive(Parser)]
#[command(
name = "pgdrift",
about = "A tool to detect and manage schema drift in PostgreSQL databases."
)]
#[command(author, version, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Discover {
#[arg(short, long, env = "DATABASE_URL")]
database_url: String,
#[arg(short, long, value_enum, default_value = "table")]
format: output::OutputFormat,
},
Analyze {
#[arg(short, long, env = "DATABASE_URL")]
database_url: String,
table: String,
column: String,
#[arg(short = 'f', long, value_enum, default_value = "table")]
format: output::OutputFormat,
#[arg(short, long, default_value = "5000")]
sample_size: usize,
},
Index {
#[arg(short, long, env = "DATABASE_URL")]
database_url: String,
table: String,
column: String,
#[arg(short = 'f', long, value_enum, default_value = "table")]
format: output::OutputFormat,
#[arg(short, long, default_value = "5000")]
sample_size: usize,
},
ScanAll {
#[arg(short, long, env = "DATABASE_URL")]
database_url: String,
#[arg(short = 'f', long, value_enum, default_value = "table")]
format: output::OutputFormat,
#[arg(short, long, default_value = "5000")]
sample_size: usize,
},
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Discover {
database_url,
format,
} => {
commands::discover::run(&database_url, format).await?;
}
Commands::Analyze {
database_url,
table,
column,
sample_size,
format,
} => {
commands::analyze::run(&database_url, &table, &column, sample_size, format).await?;
}
Commands::Index {
database_url,
table,
column,
sample_size,
format,
} => {
commands::index::run(&database_url, &table, &column, sample_size, format).await?;
}
Commands::ScanAll {
database_url,
sample_size,
format,
} => {
commands::scan_all::run(&database_url, sample_size, format).await?;
}
}
Ok(())
}