Skip to content

Commit

Permalink
Merge pull request #227 from lukemcgregor/warnandignoreononetimescrip…
Browse files Browse the repository at this point in the history
…tchanges

added switch warnandignoreononetimescriptchanges
  • Loading branch information
ferventcoder committed Apr 12, 2016
2 parents f13b1a8 + 3ed34c7 commit 3c583de
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
6 changes: 5 additions & 1 deletion product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
.Add("w|warnononetimescriptchanges",
"WarnOnOneTimeScriptChanges - Instructs RH to execute changed one time scripts (DDL/DML in Up folder) that have previously been run against the database instead of failing. A warning is logged for each one time scripts that is rerun. Defaults to false.",
option => configuration.WarnOnOneTimeScriptChanges = option != null)
//warn on changes
.Add("warnandignoreononetimescriptchanges",
"WarnAndIgnoreOnOneTimeScriptChanges - Instructs RH to ignore and update the hash of changed one time scripts (DDL/DML in Up folder) that have previously been run against the database instead of failing. A warning is logged for each one time scripts that is rerun. Defaults to false.",
option => configuration.WarnAndIgnoreOnOneTimeScriptChanges = option != null)
//silent?
.Add("silent|ni|noninteractive",
"Silent - tells RH not to ask for any input when it runs. Defaults to false.",
Expand Down Expand Up @@ -395,7 +399,7 @@ public static void show_help(string message, OptionSet option_set)
public static void init_folder(ConfigurationPropertyHolder configuration)
{
the_logger.Info("Initializing folder for roundhouse");
Container.get_an_instance_of<Initializer>().Initialize(configuration,".");
Container.get_an_instance_of<Initializer>().Initialize(configuration, ".");
Environment.Exit(0);
}

Expand Down
7 changes: 3 additions & 4 deletions product/roundhouse.tasks/Roundhouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
using infrastructure.app.logging;
using infrastructure.containers;
using infrastructure.filesystem;

using Microsoft.Build.Framework;
using migrators;

using Microsoft.Build.Utilities;

using migrators;
using resolvers;
using runners;
using Environment = environments.Environment;
Expand Down Expand Up @@ -128,6 +125,8 @@ bool ITask.Execute()

public bool WarnOnOneTimeScriptChanges { get; set; }

public bool WarnAndIgnoreOnOneTimeScriptChanges { get; set; }

public bool Silent { get; set; }

public string DatabaseType { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions product/roundhouse/consoles/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public int CommandTimeoutAdmin { get; set; }
public string SqlFilesDirectory { get; set; }
public string RepositoryPath { get; set; }
public string Version { get; set; }
public string Version { get; set; }
public string VersionFile { get; set; }
public string VersionXPath { get; set; }
public string AlterDatabaseFolderName { get; set; }
public string RunAfterCreateDatabaseFolderName { get; set; }
public string RunBeforeUpFolderName { get; set; }
public string RunBeforeUpFolderName { get; set; }
public string UpFolderName { get; set; }
public string DownFolderName { get; set; }
public string RunFirstAfterUpFolderName { get; set; }
Expand All @@ -45,6 +45,7 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public string CreateDatabaseCustomScript { get; set; }
public string OutputPath { get; set; }
public bool WarnOnOneTimeScriptChanges { get; set; }
public bool WarnAndIgnoreOnOneTimeScriptChanges { get; set; }
public bool Silent { get; set; }
public string DatabaseType { get; set; }
public bool Drop { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ConfigurationPropertyHolder
string VersionXPath { get; set; }
string AlterDatabaseFolderName { get; set; }
string RunAfterCreateDatabaseFolderName { get; set; }
string RunBeforeUpFolderName { get; set; }
string RunBeforeUpFolderName { get; set; }
string UpFolderName { get; set; }
string DownFolderName { get; set; }
string RunFirstAfterUpFolderName { get; set; }
Expand All @@ -45,6 +45,7 @@ public interface ConfigurationPropertyHolder
string CreateDatabaseCustomScript { get; set; }
string OutputPath { get; set; }
bool WarnOnOneTimeScriptChanges { get; set; }
bool WarnAndIgnoreOnOneTimeScriptChanges { get; set; }
bool Silent { get; set; }
string DatabaseType { get; set; }
bool Drop { get; set; }
Expand Down
51 changes: 29 additions & 22 deletions product/roundhouse/migrators/DefaultDatabaseMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class DefaultDatabaseMigrator : DatabaseMigrator
private readonly string custom_restore_options;
private readonly string output_path;
private readonly bool error_on_one_time_script_changes;
private readonly bool ignore_one_time_script_changes;
private bool running_in_a_transaction;
private readonly bool is_running_all_any_time_scripts;
private readonly bool is_baseline;
Expand All @@ -36,7 +37,8 @@ public DefaultDatabaseMigrator(Database database, CryptographicService crypto_pr
restore_path = configuration.RestoreFromPath;
custom_restore_options = configuration.RestoreCustomOptions;
output_path = configuration.OutputPath;
error_on_one_time_script_changes = !configuration.WarnOnOneTimeScriptChanges;
error_on_one_time_script_changes = !configuration.WarnOnOneTimeScriptChanges && !configuration.WarnAndIgnoreOnOneTimeScriptChanges;
ignore_one_time_script_changes = configuration.WarnAndIgnoreOnOneTimeScriptChanges;
is_running_all_any_time_scripts = configuration.RunAllAnyTimeScripts;
is_baseline = configuration.Baseline;
is_dryrun = configuration.DryRun;
Expand Down Expand Up @@ -111,7 +113,7 @@ public void restore_database(string restore_from_path, string restore_options)
public void set_recovery_mode(bool simple)
{
//database.open_connection(false);
Log.bound_to(this).log_an_info_event_containing("Setting recovery mode to '{0}' for database {1}.", simple ? "Simple":"Full", database.database_name );
Log.bound_to(this).log_an_info_event_containing("Setting recovery mode to '{0}' for database {1}.", simple ? "Simple" : "Full", database.database_name);
database.set_recovery_mode(simple);
//database.close_connection();
}
Expand Down Expand Up @@ -166,6 +168,7 @@ public long version_the_database(string repository_path, string repository_versi
public bool run_sql(string sql_to_run, string script_name, bool run_this_script_once, bool run_this_script_every_time, long version_id, Environment environment, string repository_version, string repository_path, ConnectionType connection_type)
{
bool this_sql_ran = false;
bool skip_run = is_baseline;

if (this_is_a_one_time_script_that_has_changes_but_has_already_been_run(script_name, sql_to_run, run_this_script_once))
{
Expand All @@ -177,6 +180,10 @@ public bool run_sql(string sql_to_run, string script_name, bool run_this_script_
database.close_connection();
throw new Exception(error_message);
}
if (ignore_one_time_script_changes)
{
skip_run = true;
}
Log.bound_to(this).log_a_warning_event_containing("{0} is a one time script that has changed since it was run.", script_name);
}

Expand All @@ -186,25 +193,25 @@ public bool run_sql(string sql_to_run, string script_name, bool run_this_script_
if (!is_dryrun)
{
Log.bound_to(this).log_an_info_event_containing(" {3} {0} on {1} - {2}.", script_name, database.server_name, database.database_name,
is_baseline ? "BASELINING: Recording" : "Running");
skip_run ? "BASELINING: Recording" : "Running");
}
if (!is_baseline)
if (!skip_run)
{
if (!is_dryrun)
{
foreach (var sql_statement in get_statements_to_run(sql_to_run))
{
try
{
database.run_sql(sql_statement, connection_type);
}
catch (Exception ex)
{
database.rollback();
record_script_in_scripts_run_errors_table(script_name, sql_to_run, sql_statement, ex.Message, repository_version, repository_path);
database.close_connection();
throw;
foreach (var sql_statement in get_statements_to_run(sql_to_run))
{
try
{
database.run_sql(sql_statement, connection_type);
}
catch (Exception ex)
{
database.rollback();

record_script_in_scripts_run_errors_table(script_name, sql_to_run, sql_statement, ex.Message, repository_version, repository_path);
database.close_connection();
throw;
}
}
}
Expand All @@ -213,11 +220,11 @@ public bool run_sql(string sql_to_run, string script_name, bool run_this_script_
Log.bound_to(this).log_a_warning_event_containing(" DryRun: {0} on {1} - {2}.", script_name, database.server_name, database.database_name);
}
}
if (!is_dryrun)
if (!is_dryrun)
{
record_script_in_scripts_run_table(script_name, sql_to_run, run_this_script_once, version_id);
this_sql_ran = true;
}
record_script_in_scripts_run_table(script_name, sql_to_run, run_this_script_once, version_id);
this_sql_ran = true;
}
}
else
{
Expand Down Expand Up @@ -366,7 +373,7 @@ private bool this_script_should_run(string script_name, string sql_to_run, bool
{
return false;
}

return true;
}

Expand Down

0 comments on commit 3c583de

Please sign in to comment.