feat: препроверка схемы перед загрузкой
This commit is contained in:
@@ -16,4 +16,58 @@ set_global_options <- function(
|
||||
shiny.port = shiny.port,
|
||||
...
|
||||
)
|
||||
}
|
||||
|
||||
#' @export
|
||||
check_and_init_scheme <- function() {
|
||||
|
||||
cli::cli_inform(c("*" = "проверка схемы..."))
|
||||
|
||||
scheme_file <- fs::path("configs/schemas", "schema.xlsx")
|
||||
hash_file <- "schema_hash.rds"
|
||||
|
||||
#
|
||||
exist_hash <- tools::md5sum(scheme_file)
|
||||
|
||||
# если первый запуск (нет файла с кешем) инициализация схемы
|
||||
if (!file.exists("schema_hash.rds") | !file.exists("scheme.rds")) {
|
||||
|
||||
init_scheme(scheme_file)
|
||||
|
||||
# в ином случае - проверяем кэш
|
||||
} else {
|
||||
|
||||
saved_hash <- readRDS("schema_hash.rds")
|
||||
|
||||
# если данные были изменены проводим реинициализацию таблицы и схемы
|
||||
if (!all(exist_hash == saved_hash)) {
|
||||
|
||||
cli::cli_inform(c(">" = "Данные схемы были изменены..."))
|
||||
init_scheme(scheme_file)
|
||||
} else {
|
||||
cli::cli_alert_success("изменений нет")
|
||||
}
|
||||
}
|
||||
|
||||
# перезаписываем файл
|
||||
saveRDS(exist_hash, hash_file)
|
||||
}
|
||||
|
||||
|
||||
init_scheme <- function(scheme_file) {
|
||||
|
||||
options(box.path = here::here())
|
||||
box::use(
|
||||
modules/db,
|
||||
helpers/scheme_generator[scheme_R6]
|
||||
)
|
||||
|
||||
con <- db$make_db_connection()
|
||||
on.exit(db$close_db_connection(con), add = TRUE)
|
||||
|
||||
cli::cli_h1("Инициализация схемы")
|
||||
schm <- scheme_R6$new(scheme_file)
|
||||
db$check_if_table_is_exist_and_init_if_not(schm, con)
|
||||
|
||||
saveRDS(schm, "scheme.rds")
|
||||
}
|
||||
Reference in New Issue
Block a user