73 lines
1.9 KiB
R
73 lines
1.9 KiB
R
#' @export
|
||
#' @description костыли для упрощения работы себе
|
||
set_global_options <- function(
|
||
SYMBOL_DELIM = "; ",
|
||
APP.DEBUG = FALSE,
|
||
APP.FILE_DB = fs::path("data.sqlite"),
|
||
shiny.host = "127.0.0.1",
|
||
shiny.port = 1337,
|
||
...
|
||
) {
|
||
options(
|
||
SYMBOL_DELIM = SYMBOL_DELIM,
|
||
APP.DEBUG = APP.DEBUG,
|
||
APP.FILE_DB = APP.FILE_DB,
|
||
shiny.host = shiny.host,
|
||
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")
|
||
} |