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

Ensure sample table check is backwards compatible #147

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions R/CohortTables.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ createCohortTables <- function(connectionDetails = NULL,

if (any(unlist(createTableFlagList, use.names = FALSE))) {
ParallelLogger::logInfo("Creating cohort tables")
createSampleTable <-
createTableFlagList$cohortSampleTable &&
cohortTableNames$cohortSampleTable != cohortTableNames$cohortTable
createSampleTable <- ifelse(
test = is.null(createTableFlagList$cohortSampleTable),
yes = FALSE,
no = (createTableFlagList$cohortSampleTable && cohortTableNames$cohortSampleTable != cohortTableNames$cohortTable)
)
sql <- SqlRender::readSql(system.file("sql/sql_server/CreateCohortTables.sql", package = "CohortGenerator", mustWork = TRUE))
sql <- SqlRender::render(
sql = sql,
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-CohortTables.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ test_that("Create cohort tables with incremental = TRUE and partial table creati
DatabaseConnector::disconnect(conn)
})

test_that("Cohort sample table does not exist for backwards compatibility", {
cohortTableNames <- getCohortTableNames(cohortTable = "cohortSampleTable")

# Remove the sample table to make sure the create cohort table works
cohortTableNames <- cohortTableNames[-which(names(cohortTableNames) == "cohortSampleTable")]

# Create the cohort tables
expect_invisible(
createCohortTables(
connectionDetails = connectionDetails,
cohortDatabaseSchema = "main",
cohortTableNames = cohortTableNames
)
)
})

# drop cohort stats tables --------------
test_that("Drop cohort stats tables", {
cohortTableNames <- getCohortTableNames(cohortTable = "cohortStatsDropTest")
Expand Down
Loading