public void UpdateDatabase() { _logger.Info("SQL connection: " + SqlUtility.SqlConnectionInfo(SqlUtility.ConnectionString)); ConnectionTesting.ValidateDbConnection(SqlUtility.ConnectionString, _sqlExecuter); _logger.Info("Preparing Rhetos database."); PrepareRhetosDatabase(); // Since IPersistenceTransaction is not registered in the parent container scope, // the commands below will not be part of a single shared database transaction. // Instead, each command will commit its changes to the database separately. _logger.Info("Cleaning old migration data."); _databaseCleaner.RemoveRedundantMigrationColumns(); _databaseCleaner.RefreshDataMigrationRows(); // Resets the data-migration optimization cache, to avoid using stale backup data from old migration tables. _logger.Info("Executing data migration scripts."); _dataMigrationFromCodeExecuter.ExecuteBeforeDataMigrationScripts(); var dataMigrationReport = _dataMigrationScriptsExecuter.Execute(); _dataMigrationFromCodeExecuter.ExecuteAfterDataMigrationScripts(); _logger.Info("Upgrading database."); try { _databaseGenerator.UpdateDatabaseStructure(); } catch (Exception mainException) { try { if (_options.RepeatDataMigrationsAfterFailedUpdate) { _dataMigrationScriptsExecuter.Undo(dataMigrationReport.CreatedScripts); } } catch (Exception cleanupException) { _logger.Info(cleanupException.ToString()); } ExceptionsUtility.Rethrow(mainException); } _logger.Info("Deleting redundant migration data."); _databaseCleaner.RemoveRedundantMigrationColumns(); _databaseCleaner.RefreshDataMigrationRows(); // Resets the data-migration optimization cache again. // Invalidation the cache *after* upgrade is useful for developers that might develop new data-migration scripts and // manually execute them on database, to avoid unintentionally using the old migration data. // The migration data might become stale on successful deployment, if any IServerInitializer plugin modifies the main data, // for example after-deploy scripts or KeepSynchronized concepts. }
public void UpdateDatabase() { _logger.Info("SQL connection: " + SqlUtility.SqlConnectionInfo(SqlUtility.ConnectionString)); ConnectionStringReport.ValidateDbConnection(_sqlExecuter); _logger.Info("Preparing Rhetos database."); PrepareRhetosDatabase(); _logger.Info("Cleaning old migration data."); _databaseCleaner.RemoveRedundantMigrationColumns(); _databaseCleaner.RefreshDataMigrationRows(); _logger.Info("Executing data migration scripts."); _dataMigrationFromCodeExecuter.ExecuteBeforeDataMigrationScripts(); var dataMigrationReport = _dataMigrationScriptsExecuter.Execute(); _dataMigrationFromCodeExecuter.ExecuteAfterDataMigrationScripts(); _logger.Info("Upgrading database."); try { _databaseGenerator.UpdateDatabaseStructure(); } catch (Exception ex) { try { _dataMigrationScriptsExecuter.Undo(dataMigrationReport.CreatedScripts); } catch (Exception undoException) { _logger.Info(undoException.ToString()); } ExceptionsUtility.Rethrow(ex); } _logger.Info("Deleting redundant migration data."); _databaseCleaner.RemoveRedundantMigrationColumns(); _databaseCleaner.RefreshDataMigrationRows(); }
public void ExecuteGenerators(bool deployDatabaseOnly) { _deployPackagesLogger.Trace("SQL connection: " + SqlUtility.SqlConnectionInfo(SqlUtility.ConnectionString)); ValidateDbConnection(); _deployPackagesLogger.Trace("Preparing Rhetos database."); PrepareRhetosDatabase(); _deployPackagesLogger.Trace("Parsing DSL scripts."); int dslModelConceptsCount = _dslModel.Concepts.Count(); _deployPackagesLogger.Trace("Application model has " + dslModelConceptsCount + " statements."); if (deployDatabaseOnly) { _deployPackagesLogger.Info("Skipped code generators (DeployDatabaseOnly)."); } else { _deployPackagesLogger.Trace("Compiling DOM assembly."); int generatedTypesCount = _domGenerator.GetTypes().Count(); if (generatedTypesCount == 0) { _deployPackagesLogger.Info("Warning: Empty assembly is generated."); } else { _deployPackagesLogger.Trace("Generated " + generatedTypesCount + " types."); } var generators = GetSortedGenerators(); foreach (var generator in generators) { _deployPackagesLogger.Trace("Executing " + generator.GetType().Name + "."); generator.Generate(); } if (!generators.Any()) { _deployPackagesLogger.Trace("No additional generators."); } } _deployPackagesLogger.Trace("Cleaning old migration data."); _databaseCleaner.RemoveRedundantMigrationColumns(); _databaseCleaner.RefreshDataMigrationRows(); _dataMigrationFromCodeExecuter.ExecuteBeforeDataMigrationScripts(); _deployPackagesLogger.Trace("Executing data migration scripts."); var dataMigrationReport = _dataMigration.Execute(); _dataMigrationFromCodeExecuter.ExecuteAfterDataMigrationScripts(); _deployPackagesLogger.Trace("Upgrading database."); try { _databaseGenerator.UpdateDatabaseStructure(); } catch (Exception ex) { try { _dataMigration.Undo(dataMigrationReport.CreatedTags); } catch (Exception undoException) { _deployPackagesLogger.Error(undoException.ToString()); } ExceptionsUtility.Rethrow(ex); } _deployPackagesLogger.Trace("Deleting redundant migration data."); _databaseCleaner.RemoveRedundantMigrationColumns(); _databaseCleaner.RefreshDataMigrationRows(); _deployPackagesLogger.Trace("Uploading DSL scripts."); UploadDslScriptsToServer(); }