Skip to content

Commit

Permalink
Add method in EngineSqlScriptBasedDbSchemaManager for parsing change …
Browse files Browse the repository at this point in the history
…log version
  • Loading branch information
filiphr committed Sep 10, 2024
1 parent 42c9189 commit 2ee613e
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ protected String getDbVersion() {
return getProperty(getSchemaVersionPropertyName(), false);
}

protected int getChangeLogVersionOrder(String changeLogVersion) {
return Integer.parseInt(changeLogVersion);
}

protected ChangeLogVersion getChangeLogVersion() {
String changeLogTableName = getChangeLogTableName();
if (changeLogTableName != null && isTablePresent(changeLogTableName)) {
Expand All @@ -199,22 +203,22 @@ protected ChangeLogVersion getChangeLogVersion() {
}
try (PreparedStatement statement = databaseConfiguration.getConnection()
.prepareStatement("select ID from " + changeLogTableName + " order by DATEEXECUTED")) {
int changeLogVersion = 0;
int latestChangeLogVersionOrder = 0;
String changeLogVersion = null;
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String changeLogVersionId = resultSet.getString(1);
int parsedChangeLogVersion = Integer.parseInt(changeLogVersionId);
if (parsedChangeLogVersion > changeLogVersion) {
int changeLogVersionOrder = getChangeLogVersionOrder(changeLogVersionId);
if (changeLogVersionOrder > latestChangeLogVersionOrder) {
// Even though we are ordering by DATEEXECUTED, and the last ID should be the last executed one.
// It is still possible that there are multiple entries with the same DATEEXECUTED value and the order might not be correct.
// e.g. MySQL 8.0 sometimes does not return the correct order.
changeLogVersion = parsedChangeLogVersion;
changeLogVersion = changeLogVersionId;
}
}
}
if (changeLogVersion > 0) {
String changeLogVersionString = String.valueOf(changeLogVersion);
return new ChangeLogVersion(changeLogVersionString, getDbVersionForChangelogVersion(changeLogVersionString));
if (changeLogVersion != null) {
return new ChangeLogVersion(changeLogVersion, getDbVersionForChangelogVersion(changeLogVersion));
}
} catch (SQLException e) {
throw new RuntimeException("Failed to get change log version from " + changeLogTableName, e);
Expand Down

0 comments on commit 2ee613e

Please sign in to comment.