Skip to content

Commit fb7ca8f

Browse files
authored
Extract checksum compatibility logic in StandardChangeLogHistoryService (liquibase#7479)
* chore: extract checksum compatibility logic in StandardChangeLogHistoryService * chore: add Javadoc and rename method to getIncompatibleDatabaseChangeLogs
1 parent b8db018 commit fb7ca8f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

liquibase-standard/src/main/java/liquibase/changelog/StandardChangeLogHistoryService.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,8 @@ public void init() throws DatabaseException {
249249
}
250250
}
251251

252-
SqlStatement databaseChangeLogStatement = new SelectFromDatabaseChangeLogStatement(
253-
new SelectFromDatabaseChangeLogStatement.ByCheckSumNotNullAndNotLike(ChecksumVersion.latest().getVersion()),
254-
new ColumnConfig().setName("MD5SUM"));
255-
List<Map<String, ?>> md5sumRS = ChangelogJdbcMdcListener.query(getDatabase(), ex -> ex.queryForList(databaseChangeLogStatement));
256-
257252
//check if any checksum is not using the current version
258-
databaseChecksumsCompatible = md5sumRS.isEmpty();
259-
253+
databaseChecksumsCompatible = getIncompatibleDatabaseChangeLogs().isEmpty();
260254

261255
} else if (!changeLogCreateAttempted) {
262256
executor.comment("Create Database Change Log Table");
@@ -516,6 +510,24 @@ protected String getContextsSize() {
516510
return CONTEXTS_SIZE;
517511
}
518512

513+
/**
514+
* Retrieves changelog entries with checksums that are not compatible with the latest checksum version.
515+
* This method can be overridden by database-specific implementations to provide custom queries for databases that
516+
* don't support standard SQL constructs (e.g., Cassandra CQL).
517+
*
518+
* @return a list of maps containing MD5SUM values for incompatible changelog entries
519+
* @throws DatabaseException if there is an error querying the database
520+
*/
521+
public List<Map<String, ?>> getIncompatibleDatabaseChangeLogs() throws DatabaseException {
522+
SqlStatement databaseChangeLogStatement = new SelectFromDatabaseChangeLogStatement(
523+
new SelectFromDatabaseChangeLogStatement.ByCheckSumNotNullAndNotLike(
524+
ChecksumVersion.latest().getVersion()
525+
),
526+
new ColumnConfig().setName("MD5SUM")
527+
);
528+
return ChangelogJdbcMdcListener.query(getDatabase(), ex -> ex.queryForList(databaseChangeLogStatement));
529+
}
530+
519531
@Override
520532
public boolean isDatabaseChecksumsCompatible() {
521533
return this.databaseChecksumsCompatible;

0 commit comments

Comments
 (0)