Skip to content

Commit

Permalink
fixes issue1
Browse files Browse the repository at this point in the history
  • Loading branch information
wshaddix committed Feb 2, 2015
1 parent c7bf8ff commit 66c202b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
16 changes: 1 addition & 15 deletions src/SqlCi.Console/ConfigurationValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,20 @@
{
internal class ConfigurationValues
{
public bool Deploy { get; set; }

internal string ConnectionString { get; set; }

internal bool Deploy { get; set; }
internal string Environment { get; set; }

internal bool GenerateScript { get; set; }

internal string ReleaseVersion { get; set; }

internal string ResetConnectionString { get; set; }

internal bool ResetDatabase { get; set; }

internal string ResetScriptsFolder { get; set; }

internal string RollBackToVersion { get; set; }

internal string ScriptsFolder { get; set; }

internal string ScriptTable { get; set; }

internal bool ShowHelp { get; set; }

internal bool ShowHistory { get; set; }

internal bool ShowVersionNumber { get; set; }

internal bool UseConfigFile { get; set; }
}
}
75 changes: 44 additions & 31 deletions src/SqlCi.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SqlCi.ScriptRunner;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -52,7 +53,11 @@ private static ConfigurationValues GetConfigurationValues(ConfigurationValues co
// load the configuration file
dynamic configuration = JObject.Parse(File.ReadAllText("config.json"));

// TODO: verify that the target environment configuration exists
// verify that the target environment configuration exists
if (null == configuration[environment])
{
throw new ConfigurationErrorsException(string.Format("There are no values for the \"{0}\" environment in the config.json file.", environment));
}

// load the config values
if (!generateOnly)
Expand Down Expand Up @@ -100,44 +105,52 @@ private static int Main(string[] args)
return 0;
}

// we need to read in the config.json file here because all other options requires that
// we know the config
GetConfigurationValues(config, args[1], config.GenerateScript);

// if the user wants to generate a script file
if (config.GenerateScript)
try
{
var fileName = string.Format("{0}_{1}_{2}.sql", DateTime.Now.ToString("yyyyMMddHHmmssfff"), config.Environment, args[2]);
File.CreateText(string.Format(@"{0}\{1}", config.ScriptsFolder, fileName));
return 0;
}
// we need to read in the config.json file here because all other options requires
// that we know the config
GetConfigurationValues(config, args[1], config.GenerateScript);

// create a script configuration
var scriptConfiguration = new ScriptConfiguration()
.WithConnectionString(config.ConnectionString)
.WithScriptsFolder(config.ScriptsFolder).WithResetDatabase(config.ResetDatabase)
.WithResetFolder(config.ResetScriptsFolder).WithReleaseNumber(config.ReleaseVersion)
.WithScriptTable(config.ScriptTable).WithEnvironment(config.Environment)
.WithResetConnectionString(config.ResetConnectionString).Verify();
// if the user wants to generate a script file
if (config.GenerateScript)
{
var fileName = string.Format("{0}_{1}_{2}.sql", DateTime.Now.ToString("yyyyMMddHHmmssfff"), config.Environment, args[2]);
File.CreateText(string.Format(@"{0}\{1}", config.ScriptsFolder, fileName));
return 0;
}

var executor = new Executor();
// create a script configuration
var scriptConfiguration = new ScriptConfiguration()
.WithConnectionString(config.ConnectionString)
.WithScriptsFolder(config.ScriptsFolder).WithResetDatabase(config.ResetDatabase)
.WithResetFolder(config.ResetScriptsFolder).WithReleaseNumber(config.ReleaseVersion)
.WithScriptTable(config.ScriptTable).WithEnvironment(config.Environment)
.WithResetConnectionString(config.ResetConnectionString).Verify();

// write any status updates that the executor sends to the console
executor.StatusUpdate += (sender, @event) => System.Console.WriteLine(@event.Status);
var executor = new Executor();

if (config.ShowHistory)
{
var runHistory = executor.GetHistory(scriptConfiguration);
ShowHistory(runHistory); return 0;
}
// write any status updates that the executor sends to the console
executor.StatusUpdate += (sender, @event) => System.Console.WriteLine(@event.Status);

if (config.ShowHistory)
{
var runHistory = executor.GetHistory(scriptConfiguration);
ShowHistory(runHistory); return 0;
}

var executionResults = executor.Execute(scriptConfiguration);
var executionResults = executor.Execute(scriptConfiguration);

// if we were successful return 0
if (executionResults.WasSuccessful) { return 0; }
// if we were successful return 0
if (executionResults.WasSuccessful) { return 0; }

// otherwise return -1 to signal an error
return -1;
// otherwise return -1 to signal an error
return -1;
}
catch (Exception ex)
{
ShowConsoleError(ex.GetBaseException().Message);
return -1;
}
}

private static void ShowConsoleError(string msg)
Expand Down
2 changes: 1 addition & 1 deletion src/SqlCi.ScriptRunner/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private void Reset()
{
// load the reset sql scripts
UpdateStatus("Loading reset script(s) from {0} ...", _scriptConfiguration.ResetFolder);
var resetScripts = LoadSqlScriptFiles(_scriptConfiguration.ResetFolder, true);
var resetScripts = LoadSqlScriptFiles(_scriptConfiguration.ResetFolder);
UpdateStatus("Loaded {0} reset script(s) from {1} ...", resetScripts.Count, _scriptConfiguration.ResetFolder);

// if there are no scripts to run, just exit
Expand Down

0 comments on commit 66c202b

Please sign in to comment.