Example #1
0
        private void ValidateDbConnection()
        {
            var connectionReport = new ConnectionStringReport(_sqlExecuter);

            if (!connectionReport.connectivity)
            {
                throw (connectionReport.exceptionRaised);
            }
            else if (!connectionReport.isDbo)
            {
                throw (new FrameworkException("Current user does not have db_owner role for the database."));
            }
        }
        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();
        }
Example #3
0
 private void ValidateDbConnection()
 {
     var connectionReport = new ConnectionStringReport(_sqlExecuter);
     if (!connectionReport.connectivity)
         throw (connectionReport.exceptionRaised);
     else if (!connectionReport.isDbo)
         throw (new FrameworkException("Current user does not have db_owner role for the database."));
 }