Skip to content

Commit

Permalink
Add switch to not store full text of scripts run (#389)
Browse files Browse the repository at this point in the history
* Add switch to not store full text of scripts run
  • Loading branch information
koenekelschot authored and erikbra committed Oct 14, 2019
1 parent 6ee5384 commit 10cbdc9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
.Add("isuptodate",
"This option prints whether there are any database updates or not, without actually running them. Other output except errors is disabled, to make it easy to use in scripts.",
option => { })
//do not store full text of run scripts
.Add("donotstorescriptsruntext",
"DoNotStoreScriptsRunText - This instructs RH to not store the full script text in the database. Defaults to false.",
option => configuration.DoNotStoreScriptsRunText = option != null)
// default encoding
.Add("defaultencoding=",
"Default encoding to use for loading script file from disk if file doesn't contain BOM. For the list of possible values see the column Name in table listed in .NET Encoding class documentation. Defaults to UTF-8",
Expand Down
2 changes: 2 additions & 0 deletions product/roundhouse.core/consoles/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public DefaultConfiguration()
public string VersionTableName { get; set; }
public string ScriptsRunTableName { get; set; }
public string ScriptsRunErrorsTableName { get; set; }
public bool DoNotStoreScriptsRunText { get; set; }
[Obsolete("Use EnvironmentNames")]
public string EnvironmentName {
get { return EnvironmentNames.SingleOrDefault(); }
Expand Down Expand Up @@ -105,6 +106,7 @@ public IDictionary<string, string> to_token_dictionary()
tokens["DisableTokenReplacement"] = DisableTokenReplacement.to_string();
tokens["DoNotAlterDatabase"] = DoNotAlterDatabase.to_string();
tokens["DoNotCreateDatabase"] = DoNotCreateDatabase.to_string();
tokens["DoNotStoreScriptsRunText"] = DoNotStoreScriptsRunText.to_string();
tokens["DownFolderName"] = DownFolderName.to_string();
tokens["Drop"] = Drop.to_string();
tokens["DryRun"] = DryRun.to_string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public interface ConfigurationPropertyHolder
string VersionTableName { get; set; }
string ScriptsRunTableName { get; set; }
string ScriptsRunErrorsTableName { get; set; }
bool DoNotStoreScriptsRunText { get; set; }
[Obsolete("Use EnvironmentNames")]
string EnvironmentName { get; set; }
IList<string> EnvironmentNames { get; }
Expand Down
15 changes: 13 additions & 2 deletions product/roundhouse.core/migrators/DefaultDatabaseMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,23 @@ public IEnumerable<string> get_statements_to_run(string sql_to_run)

public void record_script_in_scripts_run_table(string script_name, string sql_to_run, bool run_this_script_once, long version_id)
{
var hash = hash_generator.create_hash(sql_to_run, true);
if (configuration.DoNotStoreScriptsRunText)
{
sql_to_run = null;
}

Log.bound_to(this).log_a_debug_event_containing("Recording {0} script ran on {1} - {2}.", script_name, database.server_name, database.database_name);
database.insert_script_run(script_name, sql_to_run, hash_generator.create_hash(sql_to_run, true), run_this_script_once, version_id);
database.insert_script_run(script_name, sql_to_run, hash, run_this_script_once, version_id);
}

public void record_script_in_scripts_run_errors_table(string script_name, string sql_to_run, string sql_erroneous_part, string error_message, string repository_version, string repository_path)
{
if (configuration.DoNotStoreScriptsRunText)
{
sql_to_run = null;
}

Log.bound_to(this).log_a_debug_event_containing("Recording {0} script ran with error on {1} - {2}.", script_name, database.server_name, database.database_name);
database.insert_script_run_error(script_name, sql_to_run, sql_erroneous_part, error_message, repository_version, repository_path);
}
Expand Down Expand Up @@ -367,4 +378,4 @@ public bool this_is_an_environment_file_and_its_in_the_right_environment(string
return environment_file_is_in_the_right_environment;
}
}
}
}
3 changes: 3 additions & 0 deletions product/roundhouse.tasks/Roundhouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ bool ITask.Execute()

public string ScriptsRunErrorsTableName { get; set; }

public bool DoNotStoreScriptsRunText { get; set; }

[Obsolete("Use EnvironmentNames")]
public string EnvironmentName {
get { return EnvironmentNames.SingleOrDefault(); }
Expand Down Expand Up @@ -229,6 +231,7 @@ public IDictionary<string, string> to_token_dictionary()
{ nameof(DisableTokenReplacement), DisableTokenReplacement.to_string() },
{ nameof(DoNotAlterDatabase), DoNotAlterDatabase.to_string() },
{ nameof(DoNotCreateDatabase), DoNotCreateDatabase.to_string() },
{ nameof(DoNotStoreScriptsRunText), DoNotStoreScriptsRunText.to_string() },
{ nameof(DownFolderName), DownFolderName.to_string() },
{ nameof(Drop), Drop.to_string() },
{ nameof(DryRun), DryRun.to_string() },
Expand Down

0 comments on commit 10cbdc9

Please sign in to comment.