Function to Build Release Zips (#429)

* buildRelease and buildReleaseZip

* add buildRelease
This commit is contained in:
Maxim Moinat 2021-08-19 21:43:34 +02:00 committed by GitHub
parent d73a0f426d
commit b3fddfbb85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 200 additions and 25 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,21 +1,21 @@
Version: 1.0 Version: 1.0
RestoreWorkspace: Default RestoreWorkspace: Default
SaveWorkspace: Default SaveWorkspace: Default
AlwaysSaveHistory: Default AlwaysSaveHistory: Default
EnableCodeIndexing: Yes EnableCodeIndexing: Yes
UseSpacesForTab: Yes UseSpacesForTab: Yes
NumSpacesForTab: 2 NumSpacesForTab: 2
Encoding: UTF-8 Encoding: UTF-8
RnwWeave: Sweave RnwWeave: Sweave
LaTeX: XeLaTeX LaTeX: XeLaTeX
AutoAppendNewline: Yes AutoAppendNewline: Yes
StripTrailingWhitespace: Yes StripTrailingWhitespace: Yes
BuildType: Package BuildType: Package
PackageUseDevtools: Yes PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace PackageRoxygenize: rd,collate,namespace

View File

@ -1,10 +1,12 @@
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
export(buildReleaseZip)
export(createDdl) export(createDdl)
export(createForeignKeys) export(createForeignKeys)
export(createPrimaryKeys) export(createPrimaryKeys)
export(downloadCurrentDdl) export(downloadCurrentDdl)
export(executeDdl) export(executeDdl)
export(listSupportedDialects)
export(listSupportedVersions) export(listSupportedVersions)
export(parseWiki) export(parseWiki)
export(writeDdl) export(writeDdl)

88
R/buildRelease.R Normal file
View File

@ -0,0 +1,88 @@
# Copyright 2019 Observational Health Data Sciences and Informatics
#
# This file is part of CdmDdlBase
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#' Create OMOP CDM SQL files
#'
#' Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion
#' and targetDialect to the 'ddl' folder in current working directory.
#'
#' @param cdmVersion The version of the CDM you are creating, e.g. 5.3, 5.4.
#' Defaults to all supported CDM versions.
#' @param targetDialect The target dialect
#'
buildRelease <- function(cdmVersion = listSupportedVersions(),
targetDialect = listSupportedDialects()){
for (cdmVersion in cdmVersion) {
for (targetDialect in targetDialect) {
writeDdl(targetDialect = targetDialect,
cdmVersion = cdmVersion)
writePrimaryKeys(targetDialect = targetDialect,
cdmVersion = cdmVersion)
writeForeignKeys(targetDialect = targetDialect,
cdmVersion = cdmVersion)
writeIndex(targetDialect = targetDialect,
cdmVersion = cdmVersion)
}
}
}
#' Create OMOP CDM release zip
#'
#' First calls \code{buildReleaseZips} for given cdmVersions and targetDialects.
#' This writes the ddl sql files to the ddl folder.
#' Then zips all written ddl files into a release zip to given output folder.
#'
#' If no (or multiple) targetDialect is given,
#' then one zip is written with the files of all supported dialects.
#'
#' @param cdmVersion The version of the CDM you are creating, e.g. 5.3, 5.4.
#' Defaults to all supported CDM versions.
#' @param targetDialect The target dialect. Defaults to all supported dialects.
#' @param outputfolder The output folder. Defaults to "output"
#' @return A character string containing the OHDSQL DDL
#' @export
#' @examples
#' buildReleaseZip(cdmVersion='5.3', targetDialect='sql server', outputfolder='.')
#'
buildReleaseZip <- function(cdmVersion,
targetDialect = listSupportedDialects(),
outputfolder = "output"){
# argument checks
stopifnot(is.character(cdmVersion), length(cdmVersion) == 1, cdmVersion %in% listSupportedVersions())
if (!dir.exists(outputfolder)) {
dir.create(outputfolder)
}
files <- c()
for (dialect in targetDialect) {
buildRelease(cdmVersion, dialect)
files <- c(files, list.files(file.path('ddl', cdmVersion, gsub(" ", "_", dialect)),
pattern = ".*\\.sql$",
full.names = TRUE))
}
if (length(targetDialect) == 1) {
zipName <- file.path(outputfolder, paste0("OMOPCDM", "_", gsub(" ", "_", targetDialect), "_", cdmVersion, '.zip'))
} else {
zipName <- file.path(outputfolder, paste0("OMOPCDM", "_", cdmVersion, '.zip'))
}
DatabaseConnector::createZipFile(zipFile = zipName, files = files)
}

View File

@ -6,3 +6,12 @@ listSupportedVersions <- function() {
supportedVersions <- c("5.3", "5.4") supportedVersions <- c("5.3", "5.4")
return(supportedVersions) return(supportedVersions)
} }
#' List RDBMS dialects supported by this package
#'
#' @export
listSupportedDialects <- function() {
supportedDialects <- c("oracle", "postgresql", "pdw", "redshift", "impala", "netezza", "bigquery", "sql server")
return(supportedDialects)
}

View File

@ -22,6 +22,14 @@ for (cdmVersion in supportedVersions) {
} }
} }
#############
# Zipping release
# All dialects
buildReleaseZip(cdmVersion="5.3", outputfolder="output")
# One dialect
buildReleaseZip(cdmVersion="5.4", targetDialect="postgresql", outputfolder="output")
############# #############
# BE SURE TO RUN THE EXTRAS/SITEMAINTENANCE.R BEFORE CREATING THE PDF # BE SURE TO RUN THE EXTRAS/SITEMAINTENANCE.R BEFORE CREATING THE PDF

21
man/buildRelease.Rd Normal file
View File

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/buildRelease.R
\name{buildRelease}
\alias{buildRelease}
\title{Create OMOP CDM SQL files}
\usage{
buildRelease(
cdmVersion = listSupportedVersions(),
targetDialect = listSupportedDialects()
)
}
\arguments{
\item{cdmVersion}{The version of the CDM you are creating, e.g. 5.3, 5.4.
Defaults to all supported CDM versions.}
\item{targetDialect}{The target dialect}
}
\description{
Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion
and targetDialect to the 'ddl' folder in current working directory.
}

36
man/buildReleaseZip.Rd Normal file
View File

@ -0,0 +1,36 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/buildRelease.R
\name{buildReleaseZip}
\alias{buildReleaseZip}
\title{Create OMOP CDM release zip}
\usage{
buildReleaseZip(
cdmVersion,
targetDialect = listSupportedDialects(),
outputfolder = "output"
)
}
\arguments{
\item{cdmVersion}{The version of the CDM you are creating, e.g. 5.3, 5.4.
Defaults to all supported CDM versions.}
\item{targetDialect}{The target dialect. Defaults to all supported dialects.}
\item{outputfolder}{The output folder. Defaults to "output"}
}
\value{
A character string containing the OHDSQL DDL
}
\description{
First calls \code{buildReleaseZips} for given cdmVersions and targetDialects.
This writes the ddl sql files to the ddl folder.
Then zips all written ddl files into a release zip to given output folder.
}
\details{
If no (or multiple) targetDialect is given,
then one zip is written with the files of all supported dialects.
}
\examples{
buildReleaseZip(cdmVersion='5.3', targetDialect='sql server', outputfolder='.')
}

View File

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/createdDdl.R % Please edit documentation in R/createDdl.R
\name{createDdl} \name{createDdl}
\alias{createDdl} \alias{createDdl}
\alias{createPrimaryKeys} \alias{createPrimaryKeys}
@ -30,9 +30,9 @@ Dashboard.
} }
\section{Functions}{ \section{Functions}{
\itemize{ \itemize{
\item \code{createPrimaryKeys}: createPrimaryKeys asdfladsfj \item \code{createPrimaryKeys}: createPrimaryKeys Returns a string containing the OHDSQL for creation of primary keys in the OMOP CDM.
\item \code{createForeignKeys}: createForeignKeys asdfladsf \item \code{createForeignKeys}: createForeignKeys Returns a string containing the OHDSQL for creation of foreign keys in the OMOP CDM.
}} }}
\examples{ \examples{

View File

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/listSupportedVersions.R
\name{listSupportedDialects}
\alias{listSupportedDialects}
\title{List RDBMS dialects supported by this package}
\usage{
listSupportedDialects()
}
\description{
List RDBMS dialects supported by this package
}

View File

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/writeDdl.R % Please edit documentation in R/writeDDL.R
\name{writeDdl} \name{writeDdl}
\alias{writeDdl} \alias{writeDdl}
\alias{writePrimaryKeys} \alias{writePrimaryKeys}