Skip to content

Commit

Permalink
remove config_table parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Dec 18, 2023
1 parent c052d97 commit 373ea44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ async fn test_undo_redo(valve: &Valve) -> Result<(), sqlx::Error> {
}

pub async fn run_api_tests(table: &str, database: &str) -> Result<(), sqlx::Error> {
let valve = Valve::build(table, "table", database, false, false, false).await?;
let valve = Valve::build(table, database, false, false, false).await?;
// NOTE that you must use an external script to fetch the data from the database and run a diff
// against a known good sample to verify that these tests yield the expected results:
test_matching(&valve).await?;
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ impl Valve {
/// Valve struct.
pub async fn build(
table_path: &str,
// TODO: Remove the config_table parameter.
config_table: &str,
database: &str,
verbose: bool,
interactive: bool,
Expand Down Expand Up @@ -226,7 +224,7 @@ impl Valve {
rules_config,
constraints_config,
sorted_table_list,
) = read_config_files(table_path, config_table, &parser, &pool);
) = read_config_files(table_path, &parser, &pool);

let mut global_config = SerdeMap::new();
global_config.insert(
Expand Down Expand Up @@ -1949,7 +1947,6 @@ async fn get_pool_from_connection_string(database: &str) -> Result<AnyPool, sqlx
/// containing the names of the tables in the dattatabse in sorted order.
fn read_config_files(
path: &str,
config_table: &str,
parser: &StartParser,
pool: &AnyPool,
) -> (
Expand Down Expand Up @@ -1982,7 +1979,7 @@ fn read_config_files(
if path.to_lowercase().ends_with(".tsv") {
read_tsv_into_vector(path)
} else {
read_db_table_into_vector(path, config_table)
read_db_table_into_vector(path, "table")
}
};

Expand Down Expand Up @@ -4165,7 +4162,7 @@ fn read_tsv_into_vector(path: &str) -> Vec<ValveRow> {
rows
}

/// Given a database at the specified location, query the "table" table and return a vector of rows
/// Given a database at the specified location, query the given table and return a vector of rows
/// represented as ValveRows.
fn read_db_table_into_vector(database: &str, config_table: &str) -> Vec<ValveRow> {
let connection_options;
Expand Down
55 changes: 7 additions & 48 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async fn main() -> Result<(), sqlx::Error> {
let mut dump_schema = false;
let mut drop_all = false;
let mut create_only = false;
let mut config_table = String::new();
let mut initial_load = false;
let mut source = String::new();
let mut destination = String::new();
Expand Down Expand Up @@ -74,13 +73,6 @@ async fn main() -> Result<(), sqlx::Error> {
r#"Read the configuration referred to by SOURCE, and create a corresponding database in
DESTINATION but do not load it."#,
);
// TODO: Remove this option:
ap.refer(&mut config_table).add_option(
&["--config_table"],
Store,
r#"When reading configuration from a database, the name to use to refer to the main
configuration table (defaults to "table")"#,
);
ap.refer(&mut initial_load).add_option(
&["--initial_load"],
StoreTrue,
Expand Down Expand Up @@ -121,23 +113,11 @@ async fn main() -> Result<(), sqlx::Error> {
process::exit(1);
}

if config_table.trim() == "" {
config_table = "table".to_string();
}

let interactive = !yes;
if api_test {
run_api_tests(&source, &destination).await?;
} else if dump_config {
let valve = Valve::build(
&source,
&config_table,
&destination,
verbose,
initial_load,
interactive,
)
.await?;
let valve = Valve::build(&source, &destination, verbose, initial_load, interactive).await?;
let mut config = valve.global_config.clone();
let datatype_conditions =
format!("{:?}", valve.compiled_datatype_conditions).replace(r"\", r"\\");
Expand All @@ -155,38 +135,17 @@ async fn main() -> Result<(), sqlx::Error> {

let config = serde_json::to_string(&config).unwrap();
println!("{}", config);
} else if dump_schema {
let valve = Valve::build(&source, &destination, verbose, initial_load, interactive).await?;
valve.dump_schema().await?;
} else if drop_all {
let valve = Valve::build(
&source,
&config_table,
&destination,
verbose,
initial_load,
interactive,
)
.await?;
let valve = Valve::build(&source, &destination, verbose, initial_load, interactive).await?;
valve.drop_all_tables().await?;
} else if create_only {
let valve = Valve::build(
&source,
&config_table,
&destination,
verbose,
initial_load,
interactive,
)
.await?;
let valve = Valve::build(&source, &destination, verbose, initial_load, interactive).await?;
valve.create_all_tables().await?;
} else {
let valve = Valve::build(
&source,
&config_table,
&destination,
verbose,
initial_load,
interactive,
)
.await?;
let valve = Valve::build(&source, &destination, verbose, initial_load, interactive).await?;
valve.load_all_tables(true).await?;
}

Expand Down

0 comments on commit 373ea44

Please sign in to comment.