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

Script file version resolver #25

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ public static VersionResolver build(FileSystemAccess file_system, ConfigurationP
configuration_property_holder.VersionXPath,
configuration_property_holder.VersionFile);
VersionResolver dll_version_finder = new DllFileVersionResolver(file_system,
configuration_property_holder.VersionFile);
IEnumerable<VersionResolver> resolvers = new List<VersionResolver> {xml_version_finder, dll_version_finder};
configuration_property_holder.VersionFile);

VersionResolver script_number_version_finder = new ScriptfileVersionResolver(file_system,
configuration_property_holder.VersionFile,
file_system.combine_paths(configuration_property_holder.SqlFilesDirectory, configuration_property_holder.UpFolderName));
IEnumerable<VersionResolver> resolvers;
resolvers = new List<VersionResolver> { xml_version_finder, dll_version_finder, script_number_version_finder };


return new ComplexVersionResolver(resolvers);
}
Expand Down
1 change: 1 addition & 0 deletions product/roundhouse/infrastructure/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class ApplicationParameters
public static readonly string default_scripts_run_errors_table_name = "ScriptsRunErrors";
public static readonly string default_version_file = @"_BuildInfo.xml";
public static readonly string default_version_x_path = @"//buildInfo/version";
public static readonly bool default_up_script_versioning = false;
public static readonly string default_files_directory = @".";
public static readonly string default_server_name = "(local)";
public static readonly string default_output_path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\" + name;
Expand Down
2 changes: 1 addition & 1 deletion product/roundhouse/resolvers/DllFileVersionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ private bool version_file_is_dll(string version_file)
{
return file_system.get_file_extension_from(version_file).to_lower() == dll_extension;
}
}
}
}
49 changes: 49 additions & 0 deletions product/roundhouse/resolvers/ScriptfileVersionResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Text.RegularExpressions;
using roundhouse.infrastructure.filesystem;
using roundhouse.infrastructure.logging;

namespace roundhouse.resolvers
{
public class ScriptfileVersionResolver : VersionResolver
{
private string _versionFile;
private FileSystemAccess file_system;
private string upFolder;

public ScriptfileVersionResolver (FileSystemAccess file_system, string versionFile, string upFolder)
{
_versionFile = versionFile;
this.file_system = file_system;
this.upFolder = upFolder;
}

public bool meets_criteria()
{
return _versionFile.Contains("up/*.sql");
}

public string resolve_version()
{
string version = "0";
string extension = "sql";
if(file_system.directory_exists(upFolder))
{
var files = file_system.get_directory_info_from(upFolder).GetFiles("*." + extension);
long max = 0;
foreach(var file in files)
{
var match = Regex.Match(file.Name, @"(\d+)_.*\." + extension, RegexOptions.Multiline | RegexOptions.IgnoreCase);
if(match.Success)
{
long fileNumber = Convert.ToInt64(match.Groups[1].Value);
max = Math.Max(max, fileNumber);
}
}
version = max.ToString();
Log.bound_to(this).log_an_info_event_containing(" Found version {0} from up directory.", version);
}
return version;
}
}
}
1 change: 1 addition & 0 deletions product/roundhouse/roundhouse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<Compile Include="parameters\AdoNetParameter.cs" />
<Compile Include="parameters\IParameter.cs" />
<Compile Include="Migrate.cs" />
<Compile Include="resolvers\ScriptfileVersionResolver.cs" />
<Compile Include="RoundhousEFluentNHibernateDiffingType.cs" />
<Compile Include="runners\RoundhouseNHibernateCompareRunner.cs" />
<Compile Include="runners\RoundhouseRedGateCompareRunner.cs" />
Expand Down
2 changes: 1 addition & 1 deletion product/roundhouse/runners/RoundhouseMigrationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void run()
Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-'));
traverse_files_and_run_sql(known_folders.views.folder_full_path, version_id, known_folders.views, environment, new_version);
Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-'));
Log.bound_to(this).log_an_info_event_containing("Looking for {0} scripts in \"{1}\".", "Stored Procedure", known_folders.sprocs.folder_full_path);
Log.bound_to(this).log_an_info_event_containing("Looking for {0} scripts in \"{1}\".", "Stored Procedure", known_folders.sprocs.folder_full_path);
Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-'));
traverse_files_and_run_sql(known_folders.sprocs.folder_full_path, version_id, known_folders.sprocs, environment, new_version);
Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-'));
Expand Down