public void Dispose() { var roundhouseMigrate = new Migrate(); roundhouseMigrate.Set(x => x.ConnectionString = database.ConnectionString); roundhouseMigrate.GetConfiguration().DoNotCreateDatabase = true; roundhouseMigrate.GetConfiguration().Drop = true; roundhouseMigrate.GetConfiguration().WithTransaction = false; roundhouseMigrate.Run(); }
protected static Database get_assert_database() { var m = new Migrate().Set(p => { p.Logger = new ConsoleLogger(); p.DatabaseName = database_name; p.SqlFilesDirectory = sql_files_folder; p.Silent = true; p.DryRun = false; }); ApplicationConfiguraton.set_defaults_if_properties_are_not_set(m.GetConfiguration()); ApplicationConfiguraton.build_the_container(m.GetConfiguration()); return Container.get_an_instance_of<Database>(); }
/// <summary> /// Set up your migrator and call this to generate a diff file. Known limitations - will not detect size changes or renames. In other words, destructive changes will need to be done by hand. /// </summary> /// <param name="diffingType">Are you in greenfield development or have you went to production (maintenance)? Do you want it to restore during maintenance mode?</param> /// <param name="nameOfOutputScriptToCreateOrReplace">This is something like 0001_CreateTables.sql. This will end up in your up folder, assuming you have set up your migrator configuration correctly.</param> /// <param name="databaseMigrator">The Migrator to use when running.</param> /// <param name="mappingsAssembly">This is the assembly that contains your mapping files.</param> /// <param name="conventionsAssembly">This is the assembly that contains your conventions. If you do not have conventions set up, just pass null. It will use the mappingsAssembly</param> public void Run(RoundhousEFluentNHDiffingType diffingType, string nameOfOutputScriptToCreateOrReplace, Migrate databaseMigrator, Assembly mappingsAssembly, Assembly conventionsAssembly) { name_of_script_to_create = nameOfOutputScriptToCreateOrReplace; var configuration = databaseMigrator.GetConfiguration(); configuration.Silent = true; configuration.Restore = false; ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration); path_to_sql_scripts_up_folder = Path.Combine(configuration.SqlFilesDirectory, configuration.UpFolderName); databaseMigrator.Set(c => { c.Silent = true; c.VersionFile = mappingsAssembly.Location; } ); switch (diffingType) { case RoundhousEFluentNHDiffingType.InitialDevelopment: run_initial_database_setup(databaseMigrator, configuration, mappingsAssembly, conventionsAssembly); break; case RoundhousEFluentNHDiffingType.Maintenance: run_maintenance_database_setup(false, databaseMigrator, configuration, mappingsAssembly, conventionsAssembly, name_of_script_to_create); break; case RoundhousEFluentNHDiffingType.MaintenanceWithRestore: run_maintenance_database_setup(true, databaseMigrator, configuration, mappingsAssembly, conventionsAssembly, name_of_script_to_create); break; } }
public static void InitMigrationDbStructure(string connectionString) { Migrate migrator = new Migrate().Set(c => { c.Logger = new ConsoleLogger(); c.ConnectionString = connectionString; c.SqlFilesDirectory = MIGRATION_PATH; c.SprocsFolderName = @"dbo\Stored Procedures"; c.ViewsFolderName = @"dbo\Views"; c.FunctionsFolderName = @"dbo\Functions"; c.UpFolderName = @"Scripts\Migrations\up"; c.RunBeforeUpFolderName = @"Scripts\Migrations\runbeforeup"; c.RunFirstAfterUpFolderName = @"Scripts\Migrations\runfirstafterup"; c.DownFolderName = @"Scripts\Migrations\down"; c.Restore = false; c.Silent = true; c.Baseline = true; c.WithTransaction = true; c.UsingVSDBProjectScripts = true; }); var configuration = migrator.GetConfiguration(); ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration); migrator.Run(); }
public override void Context() { migrator = new Migrate().Set(p => { p.Logger = new ConsoleLogger(); p.DatabaseName = database_name; p.SqlFilesDirectory = sql_files_folder; p.Silent = true; }); migrator.Run(); ConfigurationPropertyHolder configuration_property_holder = migrator.GetConfiguration(); ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration_property_holder); db.configuration = configuration_property_holder; db.server_name = configuration_property_holder.ServerName ?? string.Empty; db.database_name = configuration_property_holder.DatabaseName ?? string.Empty; db.connection_string = configuration_property_holder.ConnectionString; db.admin_connection_string = configuration_property_holder.ConnectionStringAdmin; db.roundhouse_schema_name = configuration_property_holder.SchemaName; db.version_table_name = configuration_property_holder.VersionTableName; db.scripts_run_table_name = configuration_property_holder.ScriptsRunTableName; db.scripts_run_errors_table_name = configuration_property_holder.ScriptsRunErrorsTableName; db.command_timeout = configuration_property_holder.CommandTimeout; db.admin_command_timeout = configuration_property_holder.CommandTimeoutAdmin; db.restore_timeout = configuration_property_holder.RestoreTimeout; db.initialize_connections(configuration_property_holder); }
private static void delete_database() { ConfigurationPropertyHolder configuration_property_holder = migrator.GetConfiguration(); ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration_property_holder); db.configuration = configuration_property_holder; db.delete_database_if_it_exists(); }
public MigrationResultSet Run(string connection, string workingDirectory, string createScript, string databaseName, string server, int timeout) { var logger = new RelativityRoundHouseLogger(); //create migration agent var migrationAgent = new Migrate(); //get default round house settings var configuration = migrationAgent.GetConfiguration(); ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration); //get the action delegate settings var roundHouseService = new RoundHouseSettingsService { ServerName = server }; var roundhouseConfiguration = roundHouseService.GetRoundHouseSettings(connection, workingDirectory, createScript); //register the delegate migrationAgent.Set(roundhouseConfiguration); if (!string.IsNullOrEmpty(server)) { migrationAgent.Set(x => x.DatabaseName = databaseName); } migrationAgent.SetCustomLogging(logger); migrationAgent.Set(x => x.CommandTimeout = timeout); migrationAgent.Set(x => x.CommandTimeoutAdmin = timeout); // Update the database try { // Some googling shows that roundhouse may not be threadsafe. // This starts a lock context to prevent multiple threads running roundhouse deployments at the same time. lock (obj) { migrationAgent.Run(); } } catch (Exception e) { //This is theoretically already logged by RoundhousE, but if something in RH breaks rather than in SQL, I want to know logger.Messages.Add(new LogMessage(LogSeverity.Error, e.ToString())); return(new MigrationResultSet(false, logger.Messages)); } return(new MigrationResultSet(true, logger.Messages)); }
/// <summary> /// Set up your migrator and call this to generate a diff file. Known limitations - will not detect size changes or renames. In other words, destructive changes will need to be done by hand. /// </summary> /// <param name="databaseMigrator">The Migrator to use when running.</param> /// <param name="migrationsAssembly">This is the assembly that contains your mapping files.</param> public void Run(Migrate databaseMigrator, Assembly migrationsAssembly) { var configuration = databaseMigrator.GetConfiguration(); configuration.Silent = true; configuration.Restore = false; ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration); path_to_sql_scripts_up_folder = Path.Combine(configuration.SqlFilesDirectory, configuration.UpFolderName); databaseMigrator.Set(c => { c.Silent = true; c.VersionFile = migrationsAssembly.Location; } ); run_changes(databaseMigrator, configuration, migrationsAssembly); }