add force parameter

This commit is contained in:
Patrick Schratz 2024-07-24 18:20:45 +02:00
commit c42e2be4a6
Signed by: pat-s
GPG key ID: 3C6318841EF78925

View file

@ -1,7 +1,7 @@
#' @importFrom DBI dbConnect dbDisconnect dbWriteTable dbGetQuery dbExecute
store_build_metadata <- function(
package_name, tag, platform,
error_occurred, error) {
error_occurred, error, force = FALSE) {
# s3 <- paws.storage::s3(config = list(
# endpoint = "https://s3.eu-central-003.backblazeb2.com",
# region = "eu-central-003"
@ -15,28 +15,6 @@ store_build_metadata <- function(
port = 15432, user = "arm_binaries", password = Sys.getenv("PGPASS")
)
# NB: helper fun which should only be commented in if a new column in the DB is needed!
# columns_to_add <- list(
# c("average_build_time_per_tag", "REAL")
# )
# for (column in columns_to_add) {
# add_column_if_not_exists("/tmp/metadata.sqlite", "metadata_summary", column[1], column[2])
# }
# dbExecute(con, "BEGIN TRANSACTION")
# Create the "metadata" table if it does not exist
# dbExecute(con, "CREATE TABLE IF NOT EXISTS single_builds (
# package_name TEXT,
# tag TEXT,
# platform TEXT,
# error_occurred BOOLEAN,
# build_timestamp TEXT,
# build_duration REAL
# )")
# columns added after initial DB creation
# Create an index on the package_name and tag columns
dbExecute(con, "CREATE INDEX IF NOT EXISTS idx_metadata_package_tag ON single_builds(package_name, platform)")
@ -46,8 +24,8 @@ store_build_metadata <- function(
package_name, "' AND tag = '", tag, "'"
))
if (nrow(existing_entries) >= 1) {
cli::cli_alert_info("{.fun store_build_metadata}: Build metadata for {.field {package_name}} {.field {tag}} already exists.")
if (nrow(existing_entries) >= 1 && !force) {
cli::cli_alert_info("{.fun store_build_metadata}: Build metadata for {.field {.pkg package_name}} {.field {tag}} already exists.")
} else {
cli::cli_alert_info("{.fun store_build_metadata}: Storing build metadata for {.field {package_name}} {.field {tag}}.")
# Create a data frame with the metadata
@ -63,19 +41,10 @@ store_build_metadata <- function(
dbWriteTable(con, "single_builds", metadata, append = TRUE)
}
# dbExecute(con, "COMMIT")
# Close the SQLite connection
dbDisconnect(con)
# s3 <- paws.storage::s3(config = list(
# endpoint = "https://s3.eu-central-003.backblazeb2.com",
# region = "eu-central-003"
# ))
# s3$put_object(
# Bucket = "devxy-arm64-r-binaries-db", Key = "metadata.sqlite",
# Body = "/tmp/metadata.sqlite"
# )
return(invisible(TRUE))
}
#' @importFrom DBI dbConnect dbGetQuery