Skip to content

Commit

Permalink
fixed bug while showing history and updated help content output
Browse files Browse the repository at this point in the history
  • Loading branch information
Wes Shaddix committed Apr 30, 2014
1 parent 541543d commit 0332159
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 81 deletions.
1 change: 1 addition & 0 deletions src/SqlCi.Console/ConfigurationValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal class ConfigurationValues
internal bool ShowHistory { get; set; }
internal bool UseConfigFile { get; set; }
internal bool VersionNumber { get; set; }
internal bool GenerateScript { get; set; }
}
}
1 change: 1 addition & 0 deletions src/SqlCi.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private static OptionSet DefineOptionSet(string[] args, out ConfigurationValues
{"h|help", "show this message and exit", p => config.ShowHelp = p != null},
{"v|version", "show the version number", p => config.VersionNumber = p != null},
{"sh|showHistory", "show the history of scripts ran against the database", p => config.ShowHistory = p != null},
{"g|generateScript", "generates a new script file. Usage: g <environment> <script_name> <script_folder>", p => config.GenerateScript = p != null}
};

try
Expand Down
152 changes: 71 additions & 81 deletions src/SqlCi.ScriptRunner/ScriptConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using SqlCi.ScriptRunner.Constants;
using SqlCi.ScriptRunner.Constants;
using SqlCi.ScriptRunner.Exceptions;
using System.IO;

Expand All @@ -8,81 +7,78 @@ namespace SqlCi.ScriptRunner
public class ScriptConfiguration
{
private string _connectionString;
private string _environment;
private string _releaseNumber;
private string _resetConnectionString;
private string _scriptsFolder;
private bool _resetDatabase;
private string _resetFolder;
private string _releaseNumber;
private string _scriptsFolder;
private string _scriptTable;
private bool _resetDatabase;
private bool _verified;
private string _environment;

public string ScriptsFolder
{
get { return _scriptsFolder; }
}

public string ConnectionString
{
get { return _connectionString; }
}

public string ScriptTable
public string Environment
{
get { return _scriptTable; }
get { return _environment; }
}
public bool IsVerified
{
get { return _verified; }
}

public string ReleaseNumber
{
get { return _releaseNumber; }
}

public bool IsVerified
public string ResetConnectionString
{
get { return _verified; }
get { return _resetConnectionString; }
}

public bool ResetDatabase
{
get { return _resetDatabase; }
}

public string ResetFolder
{
get { return _resetFolder; }
}

public string Environment
public string ScriptsFolder
{
get { return _environment; }
get { return _scriptsFolder; }
}

public string ResetConnectionString
public string ScriptTable
{
get { return _resetConnectionString; }
get { return _scriptTable; }
}

public ScriptConfiguration WithConnectionString(string connectionString)
public ScriptConfiguration Verify()
{
_connectionString = connectionString;
return this;
}
// do a sanity check on our variables and make sure we have everything we need to run
// the scripts
ValidateConnectionString();
ValidateScriptsFolder();
ValidateResetFolder();
ValidateReleaseNumber();
ValidateScriptTable();
ValidateEnvironment();
ValidateResetConnectionString();

// if we got this far without errors then we are ready to run scripts
_verified = true;

public ScriptConfiguration WithScriptsFolder(string scriptsFolder)
{
_scriptsFolder = scriptsFolder;
return this;
}

public ScriptConfiguration WithResetDatabase(bool resetDatabase)
public ScriptConfiguration WithConnectionString(string connectionString)
{
_resetDatabase = resetDatabase;
_connectionString = connectionString;
return this;
}

public ScriptConfiguration WithResetFolder(string resetFolder)
public ScriptConfiguration WithEnvironment(string environment)
{
_resetFolder = resetFolder;
_environment = environment;
return this;
}

Expand All @@ -92,68 +88,49 @@ public ScriptConfiguration WithReleaseNumber(string releaseNumber)
return this;
}

public ScriptConfiguration WithScriptTable(string scriptVersionTable)
public ScriptConfiguration WithResetConnectionString(string resetConnectionString)
{
_scriptTable = scriptVersionTable;
_resetConnectionString = resetConnectionString;
return this;
}

public ScriptConfiguration WithEnvironment(string environment)
public ScriptConfiguration WithResetDatabase(bool resetDatabase)
{
_environment = environment;
_resetDatabase = resetDatabase;
return this;
}

public ScriptConfiguration WithResetConnectionString(string resetConnectionString)
public ScriptConfiguration WithResetFolder(string resetFolder)
{
_resetConnectionString = resetConnectionString;
_resetFolder = resetFolder;
return this;
}

public ScriptConfiguration Verify()
public ScriptConfiguration WithScriptsFolder(string scriptsFolder)
{
// do a sanity check on our variables and make sure we have
// everything we need to run the scripts
ValidateConnectionString();
ValidateScriptsFolder();
ValidateResetFolder();
ValidateReleaseNumber();
ValidateScriptTable();
ValidateEnvironment();
ValidateResetConnectionString();

// if we got this far without errors then we are ready to run scripts
_verified = true;

_scriptsFolder = scriptsFolder;
return this;
}

private void ValidateEnvironment()
public ScriptConfiguration WithScriptTable(string scriptVersionTable)
{
if (string.IsNullOrEmpty(_environment))
{
throw new MissingEnvironmentException(ExceptionMessages.MissingEnvironment);
}
_scriptTable = scriptVersionTable;
return this;
}

private void ValidateScriptsFolder()
private void ValidateConnectionString()
{
if (string.IsNullOrEmpty(_scriptsFolder))
{
throw new MissingScriptsFolderException(ExceptionMessages.MissingScriptsFolder);
}

if (!Directory.Exists(_scriptsFolder))
if (string.IsNullOrEmpty(_connectionString))
{
throw new ScriptsFolderDoesNotExistException(ExceptionMessages.ScriptsFolderDoesNotExist);
throw new MissingConnectionStringException(ExceptionMessages.MissingConnectionString);
}
}

private void ValidateConnectionString()
private void ValidateEnvironment()
{
if (string.IsNullOrEmpty(_connectionString))
if (string.IsNullOrEmpty(_environment))
{
throw new MissingConnectionStringException(ExceptionMessages.MissingConnectionString);
throw new MissingEnvironmentException(ExceptionMessages.MissingEnvironment);
}
}

Expand All @@ -165,11 +142,11 @@ private void ValidateReleaseNumber()
}
}

private void ValidateScriptTable()
private void ValidateResetConnectionString()
{
if (string.IsNullOrEmpty(_scriptTable))
if (_resetDatabase && string.IsNullOrEmpty(_resetConnectionString))
{
throw new MissingScriptTableException(ExceptionMessages.MissingScriptTable);
throw new MissingConnectionStringException(ExceptionMessages.MissingResetConnectionString);
}
}

Expand All @@ -186,12 +163,25 @@ private void ValidateResetFolder()
}
}

private void ValidateResetConnectionString()
private void ValidateScriptsFolder()
{
if (_resetDatabase && string.IsNullOrEmpty(_resetConnectionString))
if (string.IsNullOrEmpty(_scriptsFolder))
{
throw new MissingConnectionStringException(ExceptionMessages.MissingResetConnectionString);
throw new MissingScriptsFolderException(ExceptionMessages.MissingScriptsFolder);
}

if (!Directory.Exists(_scriptsFolder))
{
throw new ScriptsFolderDoesNotExistException(ExceptionMessages.ScriptsFolderDoesNotExist);
}
}

private void ValidateScriptTable()
{
if (string.IsNullOrEmpty(_scriptTable))
{
throw new MissingScriptTableException(ExceptionMessages.MissingScriptTable);
}
}
}
}
}

0 comments on commit 0332159

Please sign in to comment.