fix metadata overwrite logic

This commit is contained in:
Patrick Schratz 2024-07-31 13:07:04 +02:00
commit 14cf69331d
Signed by: pat-s
GPG key ID: 3C6318841EF78925

View file

@ -2,7 +2,7 @@
#' @importFrom DBI dbConnect dbDisconnect dbWriteTable dbGetQuery dbExecute
store_build_metadata <- function(
package_name, tag, platform, error_occurred,
force = FALSE, error = NA) {
force = FALSE, error = NA, build_duration = NA, size = NA) {
con <- DBI::dbConnect(RPostgres::Postgres(),
dbname = "build_metadata", host = "postgres-arm-binaries-r.devxy.io",
port = 15432, user = "arm_binaries", password = Sys.getenv("PGPASS")
@ -19,8 +19,8 @@ store_build_metadata <- function(
} else if (nrow(existing_entries) >= 1 && force) {
cli::cli_alert_info("{.fun store_build_metadata}: Force overwriting build metadata for {.pkg {package_name}} {.field {tag}} because {.code force = TRUE} was set.")
DBI::dbExecute(con, "UPDATE single_builds SET build_timestamp = $1, error_occurred = $2, error = $3, WHERE package_name = $5 and tag = $6 and platform = $7",
params = list(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), error_occurred, error, package_name, tag, platform)
DBI::dbExecute(con, "UPDATE single_builds SET build_timestamp = $1, error_occurred = $2, error = $3, build_duration = $4, size = $5 WHERE package_name = $6 and tag = $7 and platform = $8",
params = list(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), error_occurred, error, build_duration, size, package_name, tag, platform)
)
} else if (nrow(existing_entries) == 0) {
cli::cli_alert("{.fun store_build_metadata}: Storing build metadata for {.pkg {package_name}} {.field {tag}}.")
@ -32,7 +32,8 @@ store_build_metadata <- function(
error_occurred = error_occurred,
error = error,
build_timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S"),
build_duration = NA
build_duration = build_duration,
size = size
)
# Write the data frame to the SQLite database
dbWriteTable(con, "single_builds", metadata, append = TRUE)