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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ default boolean supports(String url) {

boolean getAutoCommit() throws DatabaseException;

default boolean getUseAffectedRows() throws DatabaseException {
return false;
}

String getCatalog() throws DatabaseException;

String nativeSQL(String sql) throws DatabaseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@
}
}

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

@Override
public String getCatalog() throws DatabaseException {
try {
Expand Down
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 (database.getConnection().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