diff --git a/R/CohortTables.R b/R/CohortTables.R index 8b3f1b5..27816fc 100644 --- a/R/CohortTables.R +++ b/R/CohortTables.R @@ -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, diff --git a/tests/testthat/test-CohortTables.R b/tests/testthat/test-CohortTables.R index 4294a5a..d05e4b6 100644 --- a/tests/testthat/test-CohortTables.R +++ b/tests/testthat/test-CohortTables.R @@ -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")