diff --git a/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationScriptTestBase.java b/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationScriptTestBase.java index 1fe210e..a8042af 100644 --- a/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationScriptTestBase.java +++ b/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationScriptTestBase.java @@ -104,7 +104,6 @@ protected void allScriptsShouldBeTestedAndHavePreconditionsAndAllTestedFilesIncl private void testDefinitionMigration(LiquibaseMigrationTestDefinition definition) throws SQLException, LiquibaseException { try (Connection connection = databaseHelper.getConnection()) { - definition.assertPreMigrationSchema(getDatabase(), connection); if (definition.disableReferentialIntegrityForInsertingPreMigrationData()) { setReferentialIntegrity(false); } @@ -114,11 +113,22 @@ private void testDefinitionMigration(LiquibaseMigrationTestDefinition definition } finally { setReferentialIntegrity(true); } + + definition.assertPreMigrationSchema(getDatabase(), connection); definition.assertPreMigrationData(connection); executeScript(definition); definition.assertPostMigrationSchema(getDatabase(), connection); definition.assertPostMigrationData(connection); - connection.commit(); + + if (definition.disableReferentialIntegrityForInsertingPreMigrationData()) { + setReferentialIntegrity(false); + } + try { + definition.deletePostMigrationData(connection); + connection.commit(); + } finally { + setReferentialIntegrity(true); + } } } diff --git a/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationTestDefinition.java b/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationTestDefinition.java index f209a78..7e9d394 100644 --- a/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationTestDefinition.java +++ b/src/main/java/com/tyro/oss/dbevolution/LiquibaseMigrationTestDefinition.java @@ -101,6 +101,9 @@ protected void assertPreMigrationData(Connection connection) throws SQLException protected void assertPostMigrationData(Connection connection) throws SQLException { } + protected void deletePostMigrationData(Connection connection) throws SQLException { + } + public boolean disableReferentialIntegrityForInsertingPreMigrationData() { return false; }