From 05d749530f39ac088a9c76371784ee24ffabddba Mon Sep 17 00:00:00 2001 From: Chester Husk III Date: Sun, 28 Sep 2014 22:54:20 -0500 Subject: [PATCH 1/2] start of work --- src/app/FakeLib/RoundhouseHelper.fs | 49 ++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/app/FakeLib/RoundhouseHelper.fs b/src/app/FakeLib/RoundhouseHelper.fs index 803032cffb2..a76c5400200 100644 --- a/src/app/FakeLib/RoundhouseHelper.fs +++ b/src/app/FakeLib/RoundhouseHelper.fs @@ -151,6 +151,45 @@ let RoundhouseDefaults = { WorkingDir = null TimeOut = TimeSpan.FromMinutes 5.} +let private getStringParam k (v : string)= + match isNullOrEmpty v with + | true -> None + | false -> Some (k, v) + +let getBoolParam k (v : bool) = + match v with + | true -> Some (k, String.Empty) + | false -> None + +let getIntParam k (v : int) = + Some(k, v.ToString()) + +let private serializeArgs args = + args + |> Seq.map (function + | None -> "" + | Some(k, v) -> + "/" + k + (if isNullOrEmpty v then "" + else ":" + v)) + |> separated " " + + +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 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 + + + /// This task to can be used to run [RoundhousE](http://projectroundhouse.org/) for database migrations. /// ## Parameters /// @@ -167,14 +206,10 @@ 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 = 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 From d39b2dbe403902eed7d7f0673186d1e09a3a14ec Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 29 Sep 2014 10:31:31 -0500 Subject: [PATCH 2/2] clean up the roundhouse functions. unspecified params are not passed now, and string values are quoted to prevent errant spaces from messing up argument parsing --- src/app/FakeLib/RoundhouseHelper.fs | 45 ++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/app/FakeLib/RoundhouseHelper.fs b/src/app/FakeLib/RoundhouseHelper.fs index a76c5400200..56f9251a6a7 100644 --- a/src/app/FakeLib/RoundhouseHelper.fs +++ b/src/app/FakeLib/RoundhouseHelper.fs @@ -154,25 +154,28 @@ let RoundhouseDefaults = { let private getStringParam k (v : string)= match isNullOrEmpty v with | true -> None - | false -> Some (k, v) + | false -> Some (k, sprintf "\"%s\"" v) //string escape -let getBoolParam k (v : bool) = +let private getBoolParam k (v : bool) = match v with | true -> Some (k, String.Empty) | false -> None -let getIntParam k (v : int) = +let private getIntParam k (v : int) = Some(k, v.ToString()) -let private serializeArgs args = +let private formatArgs args pre split delim = args + |> Seq.filter Option.isSome |> Seq.map (function | None -> "" | Some(k, v) -> - "/" + k + (if isNullOrEmpty v then "" - else ":" + v)) - |> separated " " - + 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 @@ -181,6 +184,26 @@ let private getParamPairs (rh: RoundhouseParams) = 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 @@ -188,6 +211,9 @@ let private getParamPairs (rh: RoundhouseParams) = 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. @@ -206,9 +232,6 @@ let private getParamPairs (rh: RoundhouseParams) = let Roundhouse setParams = let parameters = setParams RoundhouseDefaults - - - //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