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

Roundhouse Cleanup #550

Merged
merged 2 commits into from
Sep 29, 2014
Merged
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
74 changes: 66 additions & 8 deletions src/app/FakeLib/RoundhouseHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,71 @@ let RoundhouseDefaults = {
WorkingDir = null
TimeOut = TimeSpan.FromMinutes 5.}

let private getStringParam k (v : string)=
match isNullOrEmpty v with
| true -> None
| false -> Some (k, sprintf "\"%s\"" v) //string escape

let private getBoolParam k (v : bool) =
match v with
| true -> Some (k, String.Empty)
| false -> None

let private getIntParam k (v : int) =
Some(k, v.ToString())

let private formatArgs args pre split delim =
args
|> Seq.filter Option.isSome
|> Seq.map (function
| None -> ""
| Some(k, v) ->
pre + k + (if isNullOrEmpty v then ""
else sprintf "%s%s" split v))
|> separated delim

let private serializeArgs args =
formatArgs args "/" "=" " "

let private getParamPairs (rh: RoundhouseParams) =
let dbName = getStringParam "d" rh.DatabaseName
let sqlFilesDir = getStringParam "f" rh.SqlFilesDirectory
let server = getStringParam "s" rh.ServerDatabase
let connString = getStringParam "cs" rh.ConnectionString
let connStringAdmin = getStringParam "csa" rh.ConnectionStringAdmin
let cmdTimeout = getIntParam "ct" rh.CommandTimeout
let cmdTimeoutAdmin = getIntParam "ct" rh.CommandTimeoutAdmin
let dbType = getStringParam "dt" rh.DatabaseType
let outPath = getStringParam "o" rh.OutputPath
let versionFile = getStringParam "vf" rh.VersionFile
let versionXPath = getStringParam "vx" rh.VersionXPath
let repoPath = getStringParam "r" rh.RepositoryPath
let env = getStringParam "env" rh.Environment
let customCreateScript = getStringParam "cds" rh.CustomCreateScript
let restoreFilePath = getStringParam "rfp" rh.RestoreFilePath
let alterFolderPath = getStringParam "ad" rh.AlterDatabaseFolderName
let runAfterOtherTimeFolderPath = getStringParam "ra" rh.RunAfterOtherAnyTimeScriptsFolderName
let runAfterCreateFolderPath = getStringParam "racd" rh.RunAfterCreateDatabaseFolderName
let runBeforeUpFolderPath = getStringParam "rb" rh.RunBeforeUpFolderName
let upFolderPath = getStringParam "u" rh.UpFolderName
let runFirstAfterUpdateFolderPath = getStringParam "rf" rh.RunFirstAfterUpdateFolderName
let funcFolderPath = getStringParam "fu" rh.FunctionsFolderName
let viewsFolderPath = getStringParam "vw" rh.ViewsFolderName
let sprocsFolderPath = getStringParam "sp" rh.SprocsFolderName
let indexFolderPath = getStringParam "ix" rh.IndexesFolderName
let permissionsFolderPath = getStringParam "p" rh.PermissionsFolderName
let drop = getBoolParam "drop" rh.Drop
let simple = getBoolParam "simple" rh.Simple
let transaction = getBoolParam "t" rh.WithTransaction
let restore = getBoolParam "restore" rh.Restore
let silent = getBoolParam "silent" rh.Silent
let warn = getBoolParam "w" rh.WarnOnOneTimeScriptChanges

[dbName;sqlFilesDir;server;connString;connStringAdmin;cmdTimeout;cmdTimeoutAdmin;dbType;outPath;versionFile;versionXPath;repoPath;env;customCreateScript;restoreFilePath;alterFolderPath;
runAfterOtherTimeFolderPath;runAfterCreateFolderPath;runBeforeUpFolderPath;upFolderPath;runFirstAfterUpdateFolderPath;funcFolderPath;viewsFolderPath;sprocsFolderPath;indexFolderPath;
permissionsFolderPath;drop;simple;transaction;restore;silent;warn;]


/// This task to can be used to run [RoundhousE](http://projectroundhouse.org/) for database migrations.
/// ## Parameters
///
Expand All @@ -167,14 +232,7 @@ let RoundhouseDefaults = {
let Roundhouse setParams =
let parameters = setParams RoundhouseDefaults

let drop = if parameters.Drop then "/drop" else ""
let simple = if parameters.Simple then "/simple" else ""
let transaction = if parameters.WithTransaction then "/t" else ""
let restore = if parameters.Restore then "/restore" else ""
let silent = if parameters.Silent then "/silent" else ""
let warn = if parameters.WarnOnOneTimeScriptChanges then "/w" else ""

let args = sprintf "/d=%s /f=%s /s=%s /cs=%s /csa=%s /ct=%i /cta=%i /dt=%s /o=%s /vf=%s /vx=%s /r=%s /env=%s /cds=%s /rfp=%s /ad=%s /ra=%s /racd=%s /rb=%s /u=%s /rf=%s /fu=%s /vw=%s /sp=%s /ix=%s /p=%s %s %s %s %s %s %s" parameters.DatabaseName parameters.SqlFilesDirectory parameters.ServerDatabase parameters.ConnectionString parameters.ConnectionStringAdmin parameters.CommandTimeout parameters.CommandTimeoutAdmin parameters.DatabaseType parameters.OutputPath parameters.VersionFile parameters.VersionXPath parameters.RepositoryPath parameters.Environment parameters.CustomCreateScript parameters.RestoreFilePath parameters.AlterDatabaseFolderName parameters.RunAfterOtherAnyTimeScriptsFolderName parameters.RunAfterCreateDatabaseFolderName parameters.RunBeforeUpFolderName parameters.UpFolderName parameters.RunFirstAfterUpdateFolderName parameters.FunctionsFolderName parameters.ViewsFolderName parameters.SprocsFolderName parameters.IndexesFolderName parameters.PermissionsFolderName drop simple transaction restore silent warn
let args = parameters |> getParamPairs |> serializeArgs

traceStartTask "Roundhouse" args

Expand Down