Skip to content

Commit

Permalink
Added option to run scripts per master directory instead of per sub-d…
Browse files Browse the repository at this point in the history
…irectory
  • Loading branch information
siimv committed Aug 1, 2011
1 parent 7b11af6 commit bb2fde6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
6 changes: 5 additions & 1 deletion product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace roundhouse.console
using infrastructure.commandline.options;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection;
using log4net.Core;
using log4net.Repository;
using infrastructure.app.logging;
Expand Down Expand Up @@ -169,6 +169,9 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
string.Format("PermissionsFolderName - The name of the folder where you keep your permissions scripts. Will recurse through subfolders. Defaults to \"{0}\".",
ApplicationParameters.default_permissions_folder_name),
option => configuration.PermissionsFolderName = option)
.Add("pde=|perdirectoryexecution=",
"PerDirectoryExecution - If scripts should executed per master directory (true) or all by each sub directory (false). Defaults to 'false'",
option => configuration.PerMasterDirectoryExecution = option != null)

This comment has been minimized.

Copy link
@ferventcoder

ferventcoder Oct 20, 2011

Interesting... this appears to be the idea that you get everything all at the same time including subdirectories to save on recursing through. Which is not a bad idea - I had thought about doing this myself. It could make for some interesting execution that is not entirely intuitive, so I like that it is opt in.

This comment has been minimized.

Copy link
@siimv

siimv Oct 20, 2011

Owner

I added it because of our directory structure (which is a little bit borrowed from VS DB solution), where there are separate directories per schema and etc. But scripts must be still run in correct order, regardless of their directory structure (which is meant only for grouping sql scripts as developers see them) and not relying on directory processing order. But I agree that it's less intuitive when you don't know how it behaves exactly.

Configuration option name and description is still little non-intuitive and maybe confusing but at that time I couldn't come up with better one...

This comment has been minimized.

Copy link
@ferventcoder

ferventcoder Oct 21, 2011

It's all good. We'll figure out a better name :D

This comment has been minimized.

Copy link
@ferventcoder

ferventcoder Nov 11, 2011

Converting this to SearchAllSubdirectoriesInsteadOfTraverse

// roundhouse items
.Add("sc=|schema=|schemaname=",
string.Format("SchemaName - This is the schema where RH stores it's tables. Once you set this a certain way, do not change this. This is definitely running with scissors and very sharp. I am allowing you to have flexibility, but because this is a knife you can still get cut if you use it wrong. I'm just saying. You've been warned. Defaults to \"{0}\".",
Expand Down Expand Up @@ -286,6 +289,7 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
"/o[utputpath] VALUE " +
"/w[arnononetimescriptchanges] " +
"/silent " +
"/pde[PerDirectoryExecution] " +
"/d[atabase]t[ype] VALUE " +
"/drop " +
"/d[onot]c[reatedatabase] " +
Expand Down
3 changes: 2 additions & 1 deletion product/roundhouse.tasks/Roundhouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace roundhouse.tasks

public sealed class Roundhouse : ITask, ConfigurationPropertyHolder
{

#region MSBuild

public IBuildEngine BuildEngine { get; set; }
Expand Down Expand Up @@ -101,6 +100,8 @@ bool ITask.Execute()

public bool Drop { get; set; }

public bool PerMasterDirectoryExecution { get; set; }

public bool DoNotCreateDatabase { get; set; }

public string OutputPath { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion product/roundhouse/consoles/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public string ScriptsRunErrorsTableName { get; set; }
public string EnvironmentName { get; set; }
public bool Restore { get; set; }
public string RestoreFromPath { get; set; }
public bool PerMasterDirectoryExecution { get; set; }
public string RestoreFromPath { get; set; }
public string RestoreCustomOptions { get; set; }
public int RestoreTimeout { get; set; }
public string CreateDatabaseCustomScript { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface ConfigurationPropertyHolder
string ScriptsRunErrorsTableName { get; set; }
string EnvironmentName { get; set; }
bool Restore { get; set; }
bool PerMasterDirectoryExecution { get; set; }
string RestoreFromPath { get; set; }
string RestoreCustomOptions { get; set; }
int RestoreTimeout { get; set; }
Expand Down
13 changes: 10 additions & 3 deletions product/roundhouse/infrastructure/filesystem/FileSystemAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@ public interface FileSystemAccess
/// <param name="directory">Path to the directory</param>
/// <param name="pattern">Pattern or extension</param>
/// <returns>A list of files inside of an existing directory</returns>
string[] get_all_file_name_strings_in(string directory, string pattern);
string[] get_all_file_name_strings_in(string directory, string pattern);

/// <summary>
/// Gets a list of all files inside of an existing directory, includes files in subdirectories also
/// </summary>
/// <param name="directory">Path to the directory</param>
/// <param name="pattern">Pattern or extension</param>
/// <returns>A list of files inside of an existing directory</returns>
string[] get_all_file_name_strings_recurevly_in(string directory, string pattern);

#endregion

Expand All @@ -198,7 +206,6 @@ public interface FileSystemAccess
/// </summary>
/// <param name="paths">Each item in order from left to right of the path</param>
/// <returns></returns>
string combine_paths(params string[] paths);

string combine_paths(params string[] paths);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,21 @@ public string[] get_all_file_name_strings_in(string directory)
public string[] get_all_file_name_strings_in(string directory,string pattern)
{
string[] returnList = Directory.GetFiles(directory, pattern);
return returnList.OrderBy(x => x).ToArray();
return returnList.OrderBy(get_file_name_from).ToArray();
}

/// <summary>
/// Gets a list of all files inside of an existing directory, includes files in subdirectories also
/// </summary>
/// <param name="directory">Path to the directory</param>
/// <param name="pattern">Pattern or extension</param>
/// <returns>A list of files inside of an existing directory</returns>
public string[] get_all_file_name_strings_recurevly_in(string directory, string pattern)
{
string[] returnList = Directory.GetFiles(directory, pattern, SearchOption.AllDirectories);
return returnList.OrderBy(get_file_name_from).ToArray();
}

#endregion

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion product/roundhouse/runners/RoundhouseMigrationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void run()

create_change_drop_folder();
Log.bound_to(this).log_a_debug_event_containing("The change_drop (output) folder is: {0}", known_folders.change_drop.folder_full_path);
Log.bound_to(this).log_an_info_event_containing("Using per master directory execution: {0}", configuration.PerMasterDirectoryExecution);

try
{
Expand Down Expand Up @@ -243,7 +244,10 @@ public void traverse_files_and_run_sql(string directory, long version_id, Migrat
{
if (!file_system.directory_exists(directory)) return;

foreach (string sql_file in file_system.get_all_file_name_strings_in(directory, SQL_EXTENSION))
var fileNames = configuration.PerMasterDirectoryExecution
? file_system.get_all_file_name_strings_recurevly_in(directory, SQL_EXTENSION)
: file_system.get_all_file_name_strings_in(directory, SQL_EXTENSION);
foreach (string sql_file in fileNames)
{
string sql_file_text = replace_tokens(File.ReadAllText(sql_file));
Log.bound_to(this).log_a_debug_event_containing(" Found and running {0}.", sql_file);
Expand All @@ -264,6 +268,7 @@ public void traverse_files_and_run_sql(string directory, long version_id, Migrat
}
}

if (configuration.PerMasterDirectoryExecution) return;
foreach (string child_directory in file_system.get_all_directory_name_strings_in(directory))
{
traverse_files_and_run_sql(child_directory, version_id, migration_folder, migrating_environment, repository_version,connection_type);
Expand Down

0 comments on commit bb2fde6

Please sign in to comment.