From ef4ccc08a6931e2bc4f2f313ffe2eee4822e7efb Mon Sep 17 00:00:00 2001 From: ferventcoder Date: Wed, 28 Sep 2011 11:59:19 +0000 Subject: [PATCH] fix for https://github.com/chucknorris/roundhouse/issues/20 - RunAfterCreateDatabase folder --- .../0000_CreateSchemas.sql | 2 + product/roundhouse.console/Program.cs | 8 +- .../OracleDatabase.cs | 2 +- .../SqlServerDatabase.cs | 6 +- .../SqlServerDatabase.cs | 9 +- product/roundhouse.tasks/Roundhouse.cs | 2 + .../consoles/DefaultConfiguration.cs | 1 + .../roundhouse/databases/AdoNetDatabase.cs | 14 +++ product/roundhouse/databases/Database.cs | 3 +- .../roundhouse/databases/DefaultDatabase.cs | 18 +++- product/roundhouse/databases/MockDatabase.cs | 11 ++- .../databases/SqlServerLiteSpeedDatabase.cs | 9 +- .../roundhouse/folders/DefaultKnownFolders.cs | 89 ++++++++++--------- product/roundhouse/folders/KnownFolders.cs | 31 +++---- .../ApplicationConfiguraton.cs | 4 + .../ConfigurationPropertyHolder.cs | 1 + .../builders/KnownFoldersBuilder.cs | 6 +- .../infrastructure/ApplicationParameters.cs | 3 +- .../roundhouse/migrators/DatabaseMigrator.cs | 2 +- .../migrators/DefaultDatabaseMigrator.cs | 8 +- .../runners/RoundhouseMigrationRunner.cs | 16 +++- 21 files changed, 166 insertions(+), 79 deletions(-) create mode 100644 db/SQLServer/TestRoundhousE/runAfterCreateDatabase/0000_CreateSchemas.sql diff --git a/db/SQLServer/TestRoundhousE/runAfterCreateDatabase/0000_CreateSchemas.sql b/db/SQLServer/TestRoundhousE/runAfterCreateDatabase/0000_CreateSchemas.sql new file mode 100644 index 0000000..8cc5553 --- /dev/null +++ b/db/SQLServer/TestRoundhousE/runAfterCreateDatabase/0000_CreateSchemas.sql @@ -0,0 +1,2 @@ +CREATE SCHEMA [rh] +GO \ No newline at end of file diff --git a/product/roundhouse.console/Program.cs b/product/roundhouse.console/Program.cs index edaf2e1..e30f2e0 100644 --- a/product/roundhouse.console/Program.cs +++ b/product/roundhouse.console/Program.cs @@ -129,10 +129,14 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper ApplicationParameters.default_version_x_path), option => configuration.VersionXPath = option) // folders - .Add("ad=|alterdatabase=|alterdatabasefolder=|alterdatabasefoldername=", + .Add("ad=|alterdatabase=|alterdatabasefolder=|alterdatabasefoldername=", string.Format("AlterDatabaseFolderName - The name of the folder where you keep your alter database scripts. Read up on token replacement. You will want to use {{DatabaseName}} here instead of specifying a database name. Will recurse through subfolders. Defaults to \"{0}\".", ApplicationParameters.default_alter_database_folder_name), option => configuration.AlterDatabaseFolderName = option) + .Add("racd=|runaftercreatedatabase=|runaftercreatedatabasefolder=|runaftercreatedatabasefoldername=", + string.Format("RunAfterCreateDatabaseFolderName - The name of the folder where you will keep scripts that ONLY run after a database is created. Will recurse through subfolders. Defaults to \"{0}\".", + ApplicationParameters.default_run_after_create_database_folder_name), + option => configuration.RunAfterCreateDatabaseFolderName = option) .Add("u=|up=|upfolder=|upfoldername=", string.Format("UpFolderName - The name of the folder where you keep your update scripts. Will recurse through subfolders. Defaults to \"{0}\".", ApplicationParameters.default_up_folder_name), @@ -279,7 +283,7 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper "/c[onnection]s[tring]a[dministration] VALUE " + "/c[ommand]t[imeout] VALUE /c[ommand]t[imeout]a[dmin] VALUE " + "/r[epositorypath] VALUE /v[ersion]f[ile] VALUE /v[ersion]x[path] VALUE " + - "/a[lter]d[atabasefoldername] VALUE /u[pfoldername] VALUE /do[wnfoldername] VALUE " + + "/a[lter]d[atabasefoldername] /r[un]a[fter]c[reate]d[atabasefoldername] VALUE VALUE /u[pfoldername] VALUE /do[wnfoldername] VALUE " + "/r[un]f[irstafterupdatefoldername] VALUE /fu[nctionsfoldername] VALUE /v[ie]w[sfoldername] VALUE " + "/sp[rocsfoldername] VALUE /i[nde]x[foldername] VALUE /p[ermissionsfoldername] VALUE " + "/sc[hemaname] VALUE /v[ersion]t[ablename] VALUE /s[cripts]r[un]t[ablename] VALUE /s[cripts]r[un]e[rrors]t[ablename] VALUE " + diff --git a/product/roundhouse.databases.oracle/OracleDatabase.cs b/product/roundhouse.databases.oracle/OracleDatabase.cs index c4a1da0..f2df4ad 100644 --- a/product/roundhouse.databases.oracle/OracleDatabase.cs +++ b/product/roundhouse.databases.oracle/OracleDatabase.cs @@ -142,7 +142,7 @@ public override void run_sql(string sql_to_run, ConnectionType connection_type) base.run_sql(sql_to_run.Replace("\r\n", "\n"), connection_type); } - private object run_sql_scalar(string sql_to_run, ConnectionType connection_type, IList> parameters) + protected override object run_sql_scalar(string sql_to_run, ConnectionType connection_type, IList> parameters) { Log.bound_to(this).log_a_debug_event_containing("Replacing \r\n with \n to be compliant with Oracle."); //http://www.barrydobson.com/2009/02/17/pls-00103-encountered-the-symbol-when-expecting-one-of-the-following/ diff --git a/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs b/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs index 0c10a87..d1abcba 100644 --- a/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs +++ b/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs @@ -120,11 +120,15 @@ IF NOT EXISTS(SELECT * FROM sys.schemas WHERE [name] = '{0}') public override string create_database_script() { return string.Format( - @"USE master + @" DECLARE @Created bit + SET @Created = 0 IF NOT EXISTS(SELECT * FROM sys.databases WHERE [name] = '{0}') BEGIN CREATE DATABASE [{0}] + SET @Created = 1 END + + SELECT @Created ", database_name); diff --git a/product/roundhouse.databases.sqlserver2000/SqlServerDatabase.cs b/product/roundhouse.databases.sqlserver2000/SqlServerDatabase.cs index 07cc85a..b7af0a9 100644 --- a/product/roundhouse.databases.sqlserver2000/SqlServerDatabase.cs +++ b/product/roundhouse.databases.sqlserver2000/SqlServerDatabase.cs @@ -94,11 +94,16 @@ public override void run_database_specific_tasks() public override string create_database_script() { return string.Format( - @"USE master - IF NOT EXISTS(SELECT * FROM sysdatabases WHERE [name] = '{0}') + @" + DECLARE @Created bit + SET @Created = 0 + IF NOT EXISTS(SELECT * FROM sys.databases WHERE [name] = '{0}') BEGIN CREATE DATABASE [{0}] + SET @Created = 1 END + + --SELECT @Created ", database_name); } diff --git a/product/roundhouse.tasks/Roundhouse.cs b/product/roundhouse.tasks/Roundhouse.cs index ffe4fc9..30724ea 100644 --- a/product/roundhouse.tasks/Roundhouse.cs +++ b/product/roundhouse.tasks/Roundhouse.cs @@ -61,6 +61,8 @@ bool ITask.Execute() public string AlterDatabaseFolderName { get; set; } + public string RunAfterCreateDatabaseFolderName { get; set; } + public string UpFolderName { get; set; } public string DownFolderName { get; set; } diff --git a/product/roundhouse/consoles/DefaultConfiguration.cs b/product/roundhouse/consoles/DefaultConfiguration.cs index 0a58971..68be1eb 100644 --- a/product/roundhouse/consoles/DefaultConfiguration.cs +++ b/product/roundhouse/consoles/DefaultConfiguration.cs @@ -17,6 +17,7 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder public string VersionFile { get; set; } public string VersionXPath { get; set; } public string AlterDatabaseFolderName { get; set; } + public string RunAfterCreateDatabaseFolderName { get; set; } public string UpFolderName { get; set; } public string DownFolderName { get; set; } public string RunFirstAfterUpFolderName { get; set; } diff --git a/product/roundhouse/databases/AdoNetDatabase.cs b/product/roundhouse/databases/AdoNetDatabase.cs index 63cf8c9..b265b04 100644 --- a/product/roundhouse/databases/AdoNetDatabase.cs +++ b/product/roundhouse/databases/AdoNetDatabase.cs @@ -124,6 +124,20 @@ private void run_command_with(string sql_to_run,ConnectionType connection_type, } } + protected override object run_sql_scalar(string sql_to_run, ConnectionType connection_type, IList> parameters) + { + object return_value = new object(); + if (string.IsNullOrEmpty(sql_to_run)) return return_value; + + using (IDbCommand command = setup_database_command(sql_to_run, connection_type, null)) + { + return_value = command.ExecuteScalar(); + command.Dispose(); + } + + return return_value; + } + protected IDbCommand setup_database_command(string sql_to_run, ConnectionType connection_type, IEnumerable> parameters) { IDbCommand command = null; diff --git a/product/roundhouse/databases/Database.cs b/product/roundhouse/databases/Database.cs index 16a86b9..6de9d24 100644 --- a/product/roundhouse/databases/Database.cs +++ b/product/roundhouse/databases/Database.cs @@ -92,7 +92,7 @@ public interface Database : IDisposable void close_admin_connection(); void rollback(); - void create_database_if_it_doesnt_exist(string custom_create_database_script); + bool create_database_if_it_doesnt_exist(string custom_create_database_script); void set_recovery_mode(bool simple); void backup_database(string output_path_minus_database); void restore_database(string restore_from_path, string custom_restore_options); @@ -100,6 +100,7 @@ public interface Database : IDisposable void run_database_specific_tasks(); void create_or_update_roundhouse_tables(); void run_sql(string sql_to_run,ConnectionType connection_type); + object run_sql_scalar(string sql_to_run, ConnectionType connection_type); void insert_script_run(string script_name, string sql_to_run, string sql_to_run_hash, bool run_this_script_once, long version_id); void insert_script_run_error(string script_name, string sql_to_run, string sql_erroneous_part, string error_message, string repository_version, string repository_path); diff --git a/product/roundhouse/databases/DefaultDatabase.cs b/product/roundhouse/databases/DefaultDatabase.cs index 7ebdbaf..e8738ce 100644 --- a/product/roundhouse/databases/DefaultDatabase.cs +++ b/product/roundhouse/databases/DefaultDatabase.cs @@ -83,8 +83,9 @@ public void set_repository() public abstract string restore_database_script(string restore_from_path, string custom_restore_options); public abstract string delete_database_script(); - public void create_database_if_it_doesnt_exist(string custom_create_database_script) + public bool create_database_if_it_doesnt_exist(string custom_create_database_script) { + bool database_was_created = false; try { string create_script = create_database_script(); @@ -96,7 +97,12 @@ public void create_database_if_it_doesnt_exist(string custom_create_database_scr create_script = TokenReplacer.replace_tokens(configuration, create_script); } } - run_sql(create_script, ConnectionType.Admin); + + var return_value = run_sql_scalar(create_script, ConnectionType.Admin); + if (return_value !=null) + { + database_was_created = (bool) return_value; + } } catch (Exception ex) { @@ -104,6 +110,8 @@ public void create_database_if_it_doesnt_exist(string custom_create_database_scr "{0} with provider {1} does not provide a facility for creating a database at this time.{2}{3}", GetType(), provider, Environment.NewLine, ex.Message); } + + return database_was_created; } public void set_recovery_mode(bool simple) @@ -175,7 +183,13 @@ public virtual void run_sql(string sql_to_run, ConnectionType connection_type) run_sql(sql_to_run, connection_type, null); } + public virtual object run_sql_scalar(string sql_to_run,ConnectionType connection_type) + { + return run_sql_scalar(sql_to_run, connection_type, null); + } + protected abstract void run_sql(string sql_to_run, ConnectionType connection_type, IList> parameters); + protected abstract object run_sql_scalar(string sql_to_run, ConnectionType connection_type, IList> parameters); public void insert_script_run(string script_name, string sql_to_run, string sql_to_run_hash, bool run_this_script_once, long version_id) { diff --git a/product/roundhouse/databases/MockDatabase.cs b/product/roundhouse/databases/MockDatabase.cs index fe48713..7222d29 100644 --- a/product/roundhouse/databases/MockDatabase.cs +++ b/product/roundhouse/databases/MockDatabase.cs @@ -158,10 +158,12 @@ public void rollback() database.rollback(); } - public void create_database_if_it_doesnt_exist(string custom_create_database_script) + public bool create_database_if_it_doesnt_exist(string custom_create_database_script) { //TODO: Don't allow creation of the database - record everything from here on out as something that would run //database_exists = database.database_exists + return true; + //return database. } public void set_recovery_mode(bool simple) @@ -206,6 +208,13 @@ public void run_sql(string sql_to_run,ConnectionType connection_type) Log.bound_to(this).log_an_info_event_containing("Running statemtent: {0}{1}", Environment.NewLine, sql_to_run); //database.run_sql(sql_to_run); } + + public object run_sql_scalar(string sql_to_run,ConnectionType connection_type) + { + Log.bound_to(this).log_an_info_event_containing("Running statemtent: {0}{1}", Environment.NewLine, sql_to_run); + //database.run_sql(sql_to_run); + return new object(); + } public void insert_script_run(string script_name, string sql_to_run, string sql_to_run_hash, bool run_this_script_once, long version_id) { diff --git a/product/roundhouse/databases/SqlServerLiteSpeedDatabase.cs b/product/roundhouse/databases/SqlServerLiteSpeedDatabase.cs index c21a996..e1a925a 100644 --- a/product/roundhouse/databases/SqlServerLiteSpeedDatabase.cs +++ b/product/roundhouse/databases/SqlServerLiteSpeedDatabase.cs @@ -148,9 +148,9 @@ public void rollback() database.rollback(); } - public void create_database_if_it_doesnt_exist(string custom_create_database_script) + public bool create_database_if_it_doesnt_exist(string custom_create_database_script) { - database.create_database_if_it_doesnt_exist(custom_create_database_script); + return database.create_database_if_it_doesnt_exist(custom_create_database_script); } public void set_recovery_mode(bool simple) @@ -209,6 +209,11 @@ public void create_or_update_roundhouse_tables() public void run_sql(string sql_to_run,ConnectionType connection_type) { database.run_sql(sql_to_run,connection_type); + } + + public object run_sql_scalar(string sql_to_run,ConnectionType connection_type) + { + return database.run_sql_scalar(sql_to_run,connection_type); } public void insert_script_run(string script_name, string sql_to_run, string sql_to_run_hash, bool run_this_script_once, long version_id) diff --git a/product/roundhouse/folders/DefaultKnownFolders.cs b/product/roundhouse/folders/DefaultKnownFolders.cs index 687cdc1..e43ce44 100644 --- a/product/roundhouse/folders/DefaultKnownFolders.cs +++ b/product/roundhouse/folders/DefaultKnownFolders.cs @@ -1,46 +1,49 @@ -namespace roundhouse.folders -{ - public sealed class DefaultKnownFolders : KnownFolders - { - 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; +namespace roundhouse.folders +{ + public sealed class DefaultKnownFolders : KnownFolders + { + public DefaultKnownFolders( + MigrationsFolder alter_database, + MigrationsFolder run_after_create_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.run_after_create_database = run_after_create_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; - } - - public MigrationsFolder alter_database { get; private set; } - public MigrationsFolder up { get; private set; } - public MigrationsFolder down { get; private set; } - public MigrationsFolder run_first_after_up { get; private set; } - public MigrationsFolder functions { get; private set; } - public MigrationsFolder views { get; private set; } + this.indexes = indexes; + this.run_after_other_any_time_scripts = runAfterOtherAnyTimeScripts; + this.permissions = permissions; + this.change_drop = change_drop; + } + + public MigrationsFolder alter_database { get; private set; } + public MigrationsFolder run_after_create_database { get; private set; } + public MigrationsFolder up { get; private set; } + public MigrationsFolder down { get; private set; } + public MigrationsFolder run_first_after_up { get; private set; } + public MigrationsFolder functions { get; private set; } + public MigrationsFolder views { get; private set; } public MigrationsFolder sprocs { get; private set; } - public MigrationsFolder indexes { get; private set; } - public MigrationsFolder runAfterOtherAnyTimeScripts { get; private set; } - public MigrationsFolder permissions { get; private set; } - - public Folder change_drop{get; private set;} - - } + public MigrationsFolder indexes { get; private set; } + public MigrationsFolder run_after_other_any_time_scripts { get; private set; } + public MigrationsFolder permissions { get; private set; } + + public Folder change_drop{get; private set;} + + } } \ No newline at end of file diff --git a/product/roundhouse/folders/KnownFolders.cs b/product/roundhouse/folders/KnownFolders.cs index 6403404..83bbfb3 100644 --- a/product/roundhouse/folders/KnownFolders.cs +++ b/product/roundhouse/folders/KnownFolders.cs @@ -1,17 +1,18 @@ -namespace roundhouse.folders -{ - public interface KnownFolders - { - MigrationsFolder alter_database { get; } - MigrationsFolder up { get; } - MigrationsFolder down { get; } - MigrationsFolder run_first_after_up { get; } - MigrationsFolder functions { get; } - MigrationsFolder views { get; } +namespace roundhouse.folders +{ + public interface KnownFolders + { + MigrationsFolder alter_database { get; } + MigrationsFolder run_after_create_database { get; } + MigrationsFolder up { get; } + MigrationsFolder down { get; } + MigrationsFolder run_first_after_up { get; } + MigrationsFolder functions { get; } + MigrationsFolder views { get; } MigrationsFolder sprocs { get; } - MigrationsFolder indexes { get; } - MigrationsFolder runAfterOtherAnyTimeScripts { get; } - MigrationsFolder permissions { get; } - Folder change_drop { get; } - } + MigrationsFolder indexes { get; } + MigrationsFolder run_after_other_any_time_scripts { get; } + MigrationsFolder permissions { get; } + Folder change_drop { get; } + } } \ No newline at end of file diff --git a/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs b/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs index 405efd4..feeb591 100644 --- a/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs +++ b/product/roundhouse/infrastructure.app/ApplicationConfiguraton.cs @@ -48,6 +48,10 @@ public static void set_defaults_if_properties_are_not_set(ConfigurationPropertyH { configuration_property_holder.AlterDatabaseFolderName = ApplicationParameters.default_alter_database_folder_name; } + if (string.IsNullOrEmpty(configuration_property_holder.RunAfterCreateDatabaseFolderName)) + { + configuration_property_holder.RunAfterCreateDatabaseFolderName = ApplicationParameters.default_run_after_create_database_folder_name; + } if (string.IsNullOrEmpty(configuration_property_holder.UpFolderName)) { configuration_property_holder.UpFolderName = ApplicationParameters.default_up_folder_name; diff --git a/product/roundhouse/infrastructure.app/ConfigurationPropertyHolder.cs b/product/roundhouse/infrastructure.app/ConfigurationPropertyHolder.cs index 6af957d..e24ec7a 100644 --- a/product/roundhouse/infrastructure.app/ConfigurationPropertyHolder.cs +++ b/product/roundhouse/infrastructure.app/ConfigurationPropertyHolder.cs @@ -16,6 +16,7 @@ public interface ConfigurationPropertyHolder string VersionFile { get; set; } string VersionXPath { get; set; } string AlterDatabaseFolderName { get; set; } + string RunAfterCreateDatabaseFolderName { get; set; } string UpFolderName { get; set; } string DownFolderName { get; set; } string RunFirstAfterUpFolderName { get; set; } diff --git a/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs b/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs index abb2b20..3b8da4a 100644 --- a/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs +++ b/product/roundhouse/infrastructure.app/builders/KnownFoldersBuilder.cs @@ -9,7 +9,9 @@ public static class KnownFoldersBuilder public static KnownFolders build(FileSystemAccess file_system, ConfigurationPropertyHolder configuration_property_holder) { MigrationsFolder alter_database_folder = new DefaultMigrationsFolder(file_system, configuration_property_holder.SqlFilesDirectory, - configuration_property_holder.AlterDatabaseFolderName,false,false); + configuration_property_holder.AlterDatabaseFolderName,false,false); + MigrationsFolder run_after_create_database_folder = new DefaultMigrationsFolder(file_system, configuration_property_holder.SqlFilesDirectory, + configuration_property_holder.RunAfterCreateDatabaseFolderName,true,false); MigrationsFolder up_folder = new DefaultMigrationsFolder(file_system, configuration_property_holder.SqlFilesDirectory, configuration_property_holder.UpFolderName, true, false); MigrationsFolder down_folder = new DefaultMigrationsFolder(file_system, configuration_property_holder.SqlFilesDirectory, @@ -36,7 +38,7 @@ public static KnownFolders build(FileSystemAccess file_system, ConfigurationProp configuration_property_holder.ServerName), get_run_date_time_string()); - return new DefaultKnownFolders(alter_database_folder,up_folder, down_folder, run_first_folder, functions_folder, views_folder, sprocs_folder, indexes_folder, + return new DefaultKnownFolders(alter_database_folder, run_after_create_database_folder,up_folder, down_folder, run_first_folder, functions_folder, views_folder, sprocs_folder, indexes_folder, runAfterOtherAnyTimeScripts_folder, permissions_folder, change_drop_folder); } diff --git a/product/roundhouse/infrastructure/ApplicationParameters.cs b/product/roundhouse/infrastructure/ApplicationParameters.cs index 0d32d12..204bfac 100644 --- a/product/roundhouse/infrastructure/ApplicationParameters.cs +++ b/product/roundhouse/infrastructure/ApplicationParameters.cs @@ -9,6 +9,7 @@ public static class ApplicationParameters public static string name = "RoundhousE"; // defaults public static readonly string default_alter_database_folder_name = "alterDatabase"; + public static readonly string default_run_after_create_database_folder_name = "runAfterCreateDatabase"; public static readonly string default_up_folder_name = "up"; public static readonly string default_down_folder_name = "down"; public static readonly string default_run_first_after_up_folder_name = "runFirstAfterUp"; @@ -40,7 +41,7 @@ public static class ApplicationParameters public static string get_merged_assembly_name() { string merged_assembly_name = "rh"; - Log.bound_to(typeof (ApplicationParameters)).log_a_debug_event_containing("The executing assembly is \"{0}\"", + Log.bound_to(typeof(ApplicationParameters)).log_a_debug_event_containing("The executing assembly is \"{0}\"", Assembly.GetExecutingAssembly().Location); if (Assembly.GetExecutingAssembly().Location.Contains("roundhouse.dll")) { diff --git a/product/roundhouse/migrators/DatabaseMigrator.cs b/product/roundhouse/migrators/DatabaseMigrator.cs index 85cf8de..1962c07 100644 --- a/product/roundhouse/migrators/DatabaseMigrator.cs +++ b/product/roundhouse/migrators/DatabaseMigrator.cs @@ -14,7 +14,7 @@ public interface DatabaseMigrator void open_connection(bool with_transaction); void close_connection(); void backup_database_if_it_exists(); - void create_or_restore_database(string custom_create_database_script); + bool create_or_restore_database(string custom_create_database_script); void set_recovery_mode(bool simple); //void restore_database(string restore_from_path); void delete_database(); diff --git a/product/roundhouse/migrators/DefaultDatabaseMigrator.cs b/product/roundhouse/migrators/DefaultDatabaseMigrator.cs index f7debdb..6b24f21 100644 --- a/product/roundhouse/migrators/DefaultDatabaseMigrator.cs +++ b/product/roundhouse/migrators/DefaultDatabaseMigrator.cs @@ -64,14 +64,16 @@ public void close_connection() database.close_connection(); } - public void create_or_restore_database(string custom_create_database_script) + public bool create_or_restore_database(string custom_create_database_script) { + var database_created = false; Log.bound_to(this).log_an_info_event_containing("Creating {0} database on {1} server if it doesn't exist.", database.database_name, database.server_name); - database.create_database_if_it_doesnt_exist(custom_create_database_script); + database_created = database.create_database_if_it_doesnt_exist(custom_create_database_script); if (restoring_database) { + database_created = false; string custom_script = custom_restore_options; if (!configuration.DisableTokenReplacement) { @@ -79,6 +81,8 @@ public void create_or_restore_database(string custom_create_database_script) } restore_database(restore_path, custom_script); } + + return database_created; } public void backup_database_if_it_exists() diff --git a/product/roundhouse/runners/RoundhouseMigrationRunner.cs b/product/roundhouse/runners/RoundhouseMigrationRunner.cs index bf5c106..1edacf8 100644 --- a/product/roundhouse/runners/RoundhouseMigrationRunner.cs +++ b/product/roundhouse/runners/RoundhouseMigrationRunner.cs @@ -99,12 +99,14 @@ public void run() //database_migrator.backup_database_if_it_exists(); remove_share_from_change_drop_folder(); + bool database_was_created = false; + if (!dropping_the_database) { if (!dont_create_the_database) { database_migrator.open_admin_connection(); - database_migrator.create_or_restore_database(get_custom_create_database_script()); + database_was_created = database_migrator.create_or_restore_database(get_custom_create_database_script()); database_migrator.set_recovery_mode(use_simple_recovery); database_migrator.close_admin_connection(); } @@ -132,6 +134,14 @@ public void run() traverse_files_and_run_sql(known_folders.alter_database.folder_full_path, version_id, known_folders.alter_database, environment, new_version,ConnectionType.Admin); database_migrator.close_admin_connection(); + if (database_was_created) + { + 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}\". These should be one time only scripts.", "Run After Create Database", known_folders.run_after_create_database.folder_full_path); + Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-')); + traverse_files_and_run_sql(known_folders.run_after_create_database.folder_full_path, version_id, known_folders.run_after_create_database, 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}\". These should be one time only scripts.", "Update", known_folders.up.folder_full_path); Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-')); @@ -162,9 +172,9 @@ public void run() traverse_files_and_run_sql(known_folders.indexes.folder_full_path, version_id, known_folders.indexes, 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}\".", "Run after Other Anytime Scripts", known_folders.runAfterOtherAnyTimeScripts.folder_full_path); + Log.bound_to(this).log_an_info_event_containing("Looking for {0} scripts in \"{1}\".", "Run after Other Anytime Scripts", known_folders.run_after_other_any_time_scripts.folder_full_path); Log.bound_to(this).log_an_info_event_containing("{0}", "-".PadRight(50, '-')); - traverse_files_and_run_sql(known_folders.runAfterOtherAnyTimeScripts.folder_full_path, version_id, known_folders.runAfterOtherAnyTimeScripts, environment, new_version); + traverse_files_and_run_sql(known_folders.run_after_other_any_time_scripts.folder_full_path, version_id, known_folders.run_after_other_any_time_scripts, 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}\". These scripts will run every time.", "Permission", known_folders.permissions.folder_full_path);