Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore EOL changes when checking whether script has changed #104

Merged
merged 1 commit into from
Jan 19, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions product/roundhouse/migrators/DefaultDatabaseMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ private bool this_is_a_one_time_script_that_has_changes_but_has_already_been_run

private bool this_script_has_changed_since_last_run(string script_name, string sql_to_run)
{
bool hash_is_same = false;

string old_text_hash = string.Empty;
try
{
Expand All @@ -294,14 +292,44 @@ private bool this_script_has_changed_since_last_run(string script_name, string s

string new_text_hash = create_hash(sql_to_run);

if (string.Compare(old_text_hash, new_text_hash, true) == 0)
bool hash_is_same = hashes_are_equal(new_text_hash, old_text_hash);

if (!hash_is_same)
{
hash_is_same = true;
// extra checks if only line endings have changed
hash_is_same = have_same_hash_ignoring_platform(sql_to_run, old_text_hash);
if (hash_is_same)
{
Log.bound_to(this).log_a_warning_event_containing("Script {0} had different line endings than before but equal content", script_name);
}
}

return !hash_is_same;
}

private bool hashes_are_equal(string new_text_hash, string old_text_hash)
{
return string.Compare(old_text_hash, new_text_hash, true) == 0;
}

private bool have_same_hash_ignoring_platform(string sql_to_run, string old_text_hash)
{
// check with unix and windows line endings
const string line_ending_windows = "\r\n";
const string line_ending_unix = "\n";
string new_text_hash = create_hash(sql_to_run.Replace(line_ending_windows, line_ending_unix));
bool hash_is_same = hashes_are_equal(new_text_hash, old_text_hash);

if (!hash_is_same)
{
// try other way around
new_text_hash = create_hash(sql_to_run.Replace(line_ending_unix, line_ending_windows));
hash_is_same = hashes_are_equal(new_text_hash, old_text_hash);
}

return hash_is_same;
}

private bool this_script_should_run(string script_name, string sql_to_run, bool run_this_script_once, bool run_this_script_every_time)
{
if (this_is_an_every_time_script(script_name, run_this_script_every_time))
Expand Down