Skip to content

Commit

Permalink
fix: Handle results table creation more robustly
Browse files Browse the repository at this point in the history
  • Loading branch information
rogoersTPH committed May 15, 2024
1 parent 6c6affb commit 85117f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ FOREIGN KEY (experiment_id, scenario_id) REFERENCES scenarios (experiment_id, sc
## https://github.com/SwissTPH/openmalaria/wiki/MonitoringOutput#surveys

## Add experiment_id
columns[["names"]] <- c("experiment_id", columns[["names"]])
columns[["types"]] <- c("INTEGER", columns[["type"]])
colNames <- c("experiment_id", columns[["names"]])
colTypes <- c("INTEGER", columns[["types"]])
DBI::dbExecute(
conn = connection,
statement = paste0(
"CREATE TABLE IF NOT EXISTS ", paste0(tName), " (",
paste0(
columns[["names"]], " ", columns[["types"]],
colNames, " ", colTypes,
collapse = ", "
),
", ",
"FOREIGN KEY (experiment_id",
ifelse("scenario_id" %in% columns[["names"]], ", scenario_id) REFERENCES scenarios (experiment_id, scenario_id",
ifelse("scenario_id" %in% colNames, ", scenario_id) REFERENCES scenarios (experiment_id, scenario_id",
") REFERENCES experiments (experiment_id"
),
") ON DELETE CASCADE ON UPDATE CASCADE);"
Expand Down

0 comments on commit 85117f3

Please sign in to comment.