private void EnsureDatabaseHasVersionMetaData() { using (var context = new DatabaseContext(_dbConnection)) { context.NewTransaction(); _communicator.EnsureSchema(context); context.Commit(); } }
void ExecuteMigration(IMigration migration) { BeforeExecute(migration); try { using (var context = new DatabaseContext(_dbConnection)) { context.NewTransaction(); foreach (var sqlStatement in migration.SqlStatements) { try { context.ExecuteNonQuery(sqlStatement); } catch (Exception e) { throw new DatabaseMigrationException(e, @"The following SQL could not be executed: {0} Exception: {1}", sqlStatement, e); } } var currentVersion = GetDatabaseVersionNumber(context); var newVersion = currentVersion + 1; _communicator.UpdateVersion(context, newVersion); context.Commit(); } AfterExecuteSuccess(migration); } catch (Exception e) { AfterExecuteError(migration, e); throw new DatabaseMigrationException(e, "The migration {0} (db version -> {1}) could not be executed", migration.Description, migration.TargetDatabaseVersion); } }