public DefaultKnownFolders( MigrationsFolder alter_database, MigrationsFolder run_after_create_database, MigrationsFolder run_before_up, MigrationsFolder up, MigrationsFolder down, MigrationsFolder run_first_after_up, MigrationsFolder functions, MigrationsFolder views, MigrationsFolder sprocs, MigrationsFolder indexes, MigrationsFolder runAfterOtherAnyTimeScripts, MigrationsFolder permissions, MigrationsFolder before_migration, MigrationsFolder after_migration, Folder change_drop ) { this.alter_database = alter_database; this.run_after_create_database = run_after_create_database; this.run_before_up = run_before_up; this.up = up; this.down = down; this.run_first_after_up = run_first_after_up; this.functions = functions; this.views = views; this.sprocs = sprocs; this.indexes = indexes; this.run_after_other_any_time_scripts = runAfterOtherAnyTimeScripts; this.permissions = permissions; this.change_drop = change_drop; this.before_migration = before_migration; this.after_migration = after_migration; }
private bool check_folder(MigrationsFolder migration_folder) { if (!file_system.directory_exists(migration_folder.folder_full_path)) { return(true); } var file_names = file_system.get_all_file_name_strings_recurevly_in(migration_folder.folder_full_path, SQL_EXTENSION); foreach (string sql_file in file_names) { string sql_file_text = migration_runner.replace_tokens(migration_runner.get_file_text(sql_file)); bool script_should_run = database_migrator.this_script_is_new_or_updated( file_system.get_file_name_from(sql_file), sql_file_text, environment_set); if (script_should_run) { return(false); } } return(true); }
public DefaultKnownFolders( MigrationsFolder alter_database, MigrationsFolder up, MigrationsFolder down, MigrationsFolder run_first_after_up, MigrationsFolder functions, MigrationsFolder views, MigrationsFolder sprocs, MigrationsFolder indexes, MigrationsFolder runAfterOtherAnyTimeScripts, MigrationsFolder permissions, Folder change_drop ) { this.alter_database = alter_database; this.up = up; this.down = down; this.run_first_after_up = run_first_after_up; this.functions = functions; this.views = views; this.sprocs = sprocs; this.indexes = indexes; this.runAfterOtherAnyTimeScripts = runAfterOtherAnyTimeScripts; this.permissions = permissions; this.change_drop = change_drop; }
private void run_sql_and_copy_to_change_drop( long version_id, MigrationsFolder migration_folder, Environment migrating_environment, string repository_version, ConnectionType connection_type, string sql_file) { string sql_file_text = replace_tokens(get_file_text(sql_file)); log_debug_event_on_bound_logger(" 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) { copy_to_change_drop_and_log_exception(migration_folder, sql_file); } }
//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) { 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 = File.ReadAllText(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); 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.ToString()); } } } 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); } }
//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 (!does_directory_exist(directory)) { return; } var fileNames = configuration.SearchAllSubdirectoriesInsteadOfTraverse ? get_the_names_of_files_in_directory_recursively(directory) : get_the_names_of_all_files_in_directory_nonrecursively(directory); foreach (string sql_file in fileNames) { run_sql_and_copy_to_change_drop(version_id, migration_folder, migrating_environment, repository_version, connection_type, sql_file); } if (configuration.SearchAllSubdirectoriesInsteadOfTraverse) { return; } foreach (var child_directory in get_the_names_of_directories_in_directory(directory)) { traverse_files_and_run_sql(child_directory, version_id, migration_folder, migrating_environment, repository_version, connection_type); } }
//todo:down story public void traverse_files_and_run_sql(string directory, long version_id, MigrationsFolder migration_folder, EnvironmentSet migrating_environment_set, 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); try { 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_set, 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()); } } } catch (Exception ex) { Log.bound_to(this).log_an_error_event_containing(" Error running {0}. Exception: {1}", sql_file, ex); if (!configuration.ContinueOnError) { throw; } } } 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_set, repository_version, connection_type); } }
public void log_and_traverse(MigrationsFolder folder, long version_id, string new_version, ConnectionType connection_type) { log_separation_line(false, false); log_info_event_on_bound_logger("Looking for {0} scripts in \"{1}\"{2}{3}", folder.friendly_name, folder.folder_full_path, folder.should_run_items_in_folder_once ? " (one-time only scripts)." : string.Empty, folder.should_run_items_in_folder_every_time ? " (every time scripts)" : string.Empty); traverse_files_and_run_sql(folder.folder_full_path, version_id, folder, environment, new_version, connection_type); }
public void log_and_traverse(MigrationsFolder folder, long version_id, string new_version, ConnectionType connection_type) { 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}\".{2}{3}", folder.friendly_name, folder.folder_full_path, folder.should_run_items_in_folder_once ? " These should be one time only scripts." : string.Empty, folder.should_run_items_in_folder_every_time ? " These scripts will run every time" : string.Empty); Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-')); traverse_files_and_run_sql(folder.folder_full_path, version_id, folder, environment, new_version, connection_type); }
private void copy_to_change_drop_and_log_exception(MigrationsFolder migration_folder, string sql_file) { try { copy_to_change_drop_folder(sql_file, null, migration_folder, ExecutionPhase.During); } catch (Exception ex) { log_warning_event_on_bound_logger( "Unable to copy {0} to {1}. {2}{3}", sql_file, migration_folder.folder_full_path, System.Environment.NewLine, ex.to_string()); } }
public void run_out_side_of_transaction_folder(MigrationsFolder folder, long version_id, string new_version) { if (!string.IsNullOrEmpty(folder.folder_name)) { if (run_in_a_transaction) { database_migrator.close_connection(); database_migrator.open_connection(false); } log_and_traverse(folder, version_id, new_version, ConnectionType.Default); if (run_in_a_transaction) { database_migrator.close_connection(); database_migrator.open_connection(run_in_a_transaction); } } }
public DefaultKnownFolders(MigrationsFolder up, MigrationsFolder down, MigrationsFolder run_first_after_up, MigrationsFolder functions, MigrationsFolder views, MigrationsFolder sprocs, MigrationsFolder permissions, Folder change_drop ) { this.up = up; this.down = down; this.run_first_after_up = run_first_after_up; this.functions = functions; this.views = views; this.sprocs = sprocs; this.permissions = permissions; this.change_drop = change_drop; }
public DefaultKnownFolders( MigrationsFolder run_before_all, MigrationsFolder alter_database, MigrationsFolder run_after_create_database, MigrationsFolder run_before_up, MigrationsFolder up, MigrationsFolder down, MigrationsFolder run_first_after_up, MigrationsFolder functions, MigrationsFolder views, MigrationsFolder sprocs, MigrationsFolder indexes, MigrationsFolder runAfterOtherAnyTimeScripts, MigrationsFolder permissions, MigrationsFolder before_migration, MigrationsFolder after_migration, Folder change_drop ) { this.run_before_all = run_before_all; this.alter_database = alter_database; this.run_after_create_database = run_after_create_database; this.run_before_up = run_before_up; this.up = up; this.down = down; this.run_first_after_up = run_first_after_up; this.functions = functions; this.views = views; this.sprocs = sprocs; this.indexes = indexes; this.run_after_other_any_time_scripts = runAfterOtherAnyTimeScripts; this.permissions = permissions; this.change_drop = change_drop; this.before_migration = before_migration; this.after_migration = after_migration; }
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); }