Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Disable referential integrity check when deleting post migration data
Browse files Browse the repository at this point in the history
  • Loading branch information
steveorourke committed Dec 11, 2019
1 parent 0877ede commit fda2bd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit fda2bd3

Please sign in to comment.