private void run_changes(Migrate migrator, ConfigurationPropertyHolder configuration, Assembly migrations_assembly) { var files_directory = configuration.SqlFilesDirectory; configuration.SqlFilesDirectory = "."; bool restoring_the_database = RefreshDatabaseParameters.RestoreDatabase; var initial_development = RefreshDatabaseParameters.DropDatabaseFirst; if (initial_development) { migrator.RunDropCreate(); } else if (restoring_the_database) { configuration.Restore = true; migrator.RunRestore(); } else { migrator.Run(); } generate_database_changes(migrations_assembly); Console.WriteLine("NOTE: To regenerate files you need to first delete them from the file system."); configuration.SqlFilesDirectory = files_directory; configuration.Restore = false; migrator.Run(); }
public void Deploy(string schemaScriptsFolder, string repository = "", bool dropDatabase = false) { if (schemaScriptsFolder == string.Empty) { schemaScriptsFolder = Assembly.GetExecutingAssembly().Directory(); } if (!Directory.Exists(schemaScriptsFolder)) { throw new DirectoryNotFoundException( string.Format( "Database schema scripts folder {0}\r\ndoes not exist", schemaScriptsFolder)); } var roundhouseMigrate = new Migrate(); if (DatabaseFolderStructure != null) { DatabaseFolderStructure.SetMigrateFolders(roundhouseMigrate, schemaScriptsFolder); } if (databaseRestoreOptions != null) { databaseRestoreOptions.SetRunRestoreOptions(roundhouseMigrate); } roundhouseMigrate.Set(x => x.ConnectionString = this.ConnectionString) .Set(x => x.SqlFilesDirectory = schemaScriptsFolder) .Set(x => x.VersionFile = Path.Combine(schemaScriptsFolder, "_BuildInfo.txt")) .Set(x => x.WithTransaction = WithTransaction) .Set(x => x.Silent = true) .Set(x => x.RecoveryMode = RecoveryMode.NoChange) .Set(x => x.RepositoryPath = repository) .Set(x => x.WarnOnOneTimeScriptChanges = WarnOnOneTimeScriptChanges) .Set(x => x.DisableTokenReplacement = true) .Set(x => x.Drop = dropDatabase) .SetCustomLogging(logger); if (databaseRestoreOptions != null) { roundhouseMigrate.RunRestore(); } else { roundhouseMigrate.Run(); } }
// maintenance database setup private void run_maintenance_database_setup(bool restoring_the_database, Migrate migrator, ConfigurationPropertyHolder configuration, Assembly mappings_assembly, Assembly conventions_assembly, string name_of_script) { var updateScriptFileName = Path.Combine(path_to_sql_scripts_up_folder, name_of_script); if (File.Exists(updateScriptFileName)) { File.Delete(updateScriptFileName); } if (restoring_the_database) { configuration.Restore = true; migrator.RunRestore(); } upgrade_database_schema(configuration.DatabaseName, mappings_assembly, conventions_assembly); configuration.Restore = false; migrator.Run(); }
public void Deploy(string schemaScriptsFolder, string repository = "", bool dropDatabase = false, TimeSpan?commandTimeout = null) { if (commandTimeout == null) { commandTimeout = TimeSpan.FromSeconds(30); } if (schemaScriptsFolder == string.Empty) { schemaScriptsFolder = Assembly.GetExecutingAssembly().Directory(); } if (!Directory.Exists(schemaScriptsFolder)) { throw new DirectoryNotFoundException( string.Format( "Database schema scripts folder {0}\r\ndoes not exist", schemaScriptsFolder)); } var roundhouseMigrate = new Migrate(); if (DatabaseFolderStructure != null) { DatabaseFolderStructure.SetMigrateFolders(roundhouseMigrate, schemaScriptsFolder); } if (databaseRestoreOptions != null) { databaseRestoreOptions.SetRunRestoreOptions(roundhouseMigrate); } roundhouseMigrate.Set(x => x.ConnectionString = ConnectionString) .Set(x => x.SqlFilesDirectory = schemaScriptsFolder) .Set(x => x.VersionFile = Path.Combine(schemaScriptsFolder, "_BuildInfo.txt")) .Set(x => x.WithTransaction = WithTransaction) .Set(x => x.Silent = true) .Set(x => x.CommandTimeout = Convert.ToInt32(commandTimeout.Value.TotalSeconds)) .Set(x => { if (!string.IsNullOrEmpty(OutputPath)) { x.OutputPath = OutputPath; } }) .Set(x => { var createDatabaseCustomScript = Path.Combine(schemaScriptsFolder, "CreateDatabase.sql"); if (File.Exists(createDatabaseCustomScript)) { x.CreateDatabaseCustomScript = createDatabaseCustomScript; } }) .Set(x => x.RecoveryMode = RecoveryMode.NoChange) .Set(x => x.RepositoryPath = repository) .Set(x => x.WarnOnOneTimeScriptChanges = WarnOnOneTimeScriptChanges) .Set(x => x.DisableTokenReplacement = true) .Set(x => x.Drop = dropDatabase) .Set(x => x.DisableOutput = true) .Set(x => x.DefaultEncoding = Encoding.Default) .SetCustomLogging(logger); if (databaseRestoreOptions != null) { roundhouseMigrate.RunRestore(); } else { roundhouseMigrate.Run(); } }