public RoundhouseMigrationRunner( string repository_path, Environment environment, KnownFolders known_folders, FileSystemAccess file_system, DatabaseMigrator database_migrator, VersionResolver version_resolver, bool silent, bool dropping_the_database, bool dont_create_the_database, bool run_in_a_transaction, bool use_simple_recovery, ConfigurationPropertyHolder configuration) { this.known_folders = known_folders; this.repository_path = repository_path; this.environment = environment; this.file_system = file_system; this.database_migrator = database_migrator; this.version_resolver = version_resolver; this.silent = silent; this.dropping_the_database = dropping_the_database; this.dont_create_the_database = dont_create_the_database; this.run_in_a_transaction = run_in_a_transaction; this.use_simple_recovery = use_simple_recovery; this.configuration = configuration; }
public void traverse_files_and_run_sql(string directory, long version_id, MigrationsFolder migration_folder, Environment migrating_environment, string repository_version,ConnectionType connection_type) { if (!file_system.directory_exists(directory)) return; foreach (string sql_file in file_system.get_all_file_name_strings_in(directory, SQL_EXTENSION)) { string sql_file_text = replace_tokens(get_file_text(sql_file)); Log.bound_to(this).log_a_debug_event_containing(" Found and running {0}.", sql_file); bool the_sql_ran = database_migrator.run_sql(sql_file_text, file_system.get_file_name_from(sql_file), migration_folder.should_run_items_in_folder_once, migration_folder.should_run_items_in_folder_every_time, version_id, migrating_environment, repository_version, repository_path,connection_type); if (the_sql_ran) { try { copy_to_change_drop_folder(sql_file, migration_folder); } catch (Exception ex) { Log.bound_to(this).log_a_warning_event_containing("Unable to copy {0} to {1}. {2}{3}", sql_file, migration_folder.folder_full_path, System.Environment.NewLine, ex.to_string()); } } } 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); } }
//todo: understand what environment you are deploying to so you can decide what to run - it was suggested there be a specific tag in the file name. Like vw_something.ENV.sql and that be a static "ENV". Then to key off of the actual environment name on the front of the file (ex. TEST.vw_something.ENV.sql) //todo:down story public void traverse_files_and_run_sql(string directory, long version_id, MigrationsFolder migration_folder, Environment migrating_environment, string repository_version) { traverse_files_and_run_sql(directory,version_id,migration_folder,migrating_environment,repository_version,ConnectionType.Default); }
//todo:down story public void traverse_files_and_run_sql(string directory, long version_id, MigrationsFolder migration_folder, Environment migrating_environment, string repository_version, ConnectionType connection_type) { if (!file_system.directory_exists(directory)) { return; } var fileNames = configuration.SearchAllSubdirectoriesInsteadOfTraverse ? 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(get_file_text(sql_file)); Log.bound_to(this).log_a_debug_event_containing(" Found and running {0}.", sql_file); bool the_sql_ran = database_migrator.run_sql(sql_file_text, file_system.get_file_name_from(sql_file), migration_folder.should_run_items_in_folder_once, migration_folder.should_run_items_in_folder_every_time, version_id, migrating_environment, repository_version, repository_path, connection_type); if (the_sql_ran) { try { copy_to_change_drop_folder(sql_file, migration_folder); } catch (Exception ex) { Log.bound_to(this).log_a_warning_event_containing("Unable to copy {0} to {1}. {2}{3}", sql_file, migration_folder.folder_full_path, System.Environment.NewLine, ex.to_string()); } } } if (configuration.SearchAllSubdirectoriesInsteadOfTraverse) { 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); } }