Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent error when unlocking the changelog in MySQL affects zero rows and useAffectedRows is true. Fixes #5502 #5777

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,9 @@ public boolean supportsCreateIfNotExists(Class<? extends DatabaseObject> type) {
public boolean supportsDatabaseChangeLogHistory() {
return true;
}

public boolean getUseAffectedRows() throws DatabaseException {
filipelautert marked this conversation as resolved.
Show resolved Hide resolved
return getConnection().getURL().contains("useAffectedRows=true");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import liquibase.database.core.DB2Database;
import liquibase.database.core.DerbyDatabase;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.MySQLDatabase;
import liquibase.diff.output.DiffOutputControl;
import liquibase.diff.output.changelog.ChangeGeneratorFactory;
import liquibase.exception.DatabaseException;
Expand Down Expand Up @@ -370,6 +371,16 @@ public void releaseLock() throws LockException {
database.rollback();
SqlStatement unlockStatement = new UnlockDatabaseChangeLogStatement();
int updatedRows = ChangelogJdbcMdcListener.query(database, ex -> ex.update(unlockStatement));
if ((updatedRows == 0) && (database instanceof MySQLDatabase)) {
Scope.getCurrentScope().getLog(getClass()).fine(
"Database did not return a proper row count (Might have useAffectedRows enabled.)"
);
// NOTE: if using useAffectedRows, MySQL will return 0 rows affected if the changelog lock was not set or already released
if (((MySQLDatabase) database).getUseAffectedRows()) {
// Assume the lock was released successfully
updatedRows = 1;
}
}
if ((updatedRows == -1) && (database instanceof MSSQLDatabase)) {
Scope.getCurrentScope().getLog(getClass()).fine(
"Database did not return a proper row count (Might have NOCOUNT enabled.)"
Expand Down
Loading