Open aylapear opened 1 year ago
This can be improved upon so each validation table has a primary key. Though it is known that the species_synonms table doesn't have a valid primary key anymore as there is some type of duplication in the table.
Only a few tables have been looked at and a primary key was picked as they are the more used tables at this point. Could take the time to go through each table and determine primary keys for the rest.
Only the primary keys are being set. Could expand the list into a table and set the datatype for each table, foreign keys and more but it would take extensive time to compile that data for it to be used in an automated capacity.
if (!is.null(validation_data[[i]])) {
query <- paste0(
"CREATE TABLE [", names(validation_data[i]),
"] (", paste(colnames(dt), collapse = ", "),
", PRIMARY KEY (", validation_data[[i]], "))"
)
DBI::dbExecute(con, query)
}
DBI::dbWriteTable(con,
names(validation_data[i]), value = dt, append = TRUE, row.names = FALSE
)
Tables with a primary key don't have the data types for each column set but ones without a primary key do have the data types of each column set because of how the DBI::dbWriteTable
function works.
Since the database is being created in its entirety each time and not being added to this should be fine but could be a future improvement.
Currently the tables are created by passing a list of the table names and the corresponding primary keys