Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write get_module_settings #22

Open
ChemiKyle opened this issue Dec 16, 2021 · 0 comments
Open

Write get_module_settings #22

ChemiKyle opened this issue Dec 16, 2021 · 0 comments

Comments

@ChemiKyle
Copy link
Contributor

It would be nice to have automated reporting of which hosts are running outdated modules. This may also serve as a precursor to sync_module_settings_between_projects, though it looks like that will

Here's a very basic implementation:

#' Get all module setting information
#'
#' @param conn a DBI database connection to a REDCap database
#'
#' @return A dataframe of all module settings on the specified host
#'
#' @export
#' @examples
#' \dontrun{
#' conn <- get_redcap_db_connection()
#' module_settings <- get_redcap_module_settings(conn)
#' }
get_redcap_module_settings <- function(conn) {
  sql <- paste("SELECT * FROM redcap_external_modules as em",
               "INNER JOIN (SELECT * FROM redcap_external_module_settings) as ems",
               "ON em.external_module_id = ems.external_module_id"
               )
  df <- DBI::dbGetQuery(conn, sql)
  # note external_module_id is duplicated,
  return(df)
}

And here is a use case:

library(tidyverse)
library(redcapcustodian)
library(dotenv)

load_dot_env("testing.env")

conn <- connect_to_redcap_db()

module_versions_on_host <- get_redcap_module_settings(conn) %>%
  filter(key == "version") %>%
  select(directory_prefix, version = value) %>%
  mutate(host = Sys.getenv("INSTANCE"))

DBI::dbDisconnect(conn)

# repeat this over a list of env files, rbind to get a complete list of module settings on each host

# Get latest tag from org's repo for directory_prefix - possibly pull this from site dir - via github API
# anti_join or filter with module_versions_on_host to get outdated modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant