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

Make lock granted time be consistent with date executed time. Modify listLocks message. LB-2126 #2217

Merged
merged 4 commits into from Jan 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion liquibase-core/src/main/java/liquibase/Liquibase.java
Expand Up @@ -1942,12 +1942,13 @@ public void reportLocks(PrintStream out) throws LiquibaseException {
+ "@" + getDatabase().getConnection().getURL());
if (locks.length == 0) {
out.println(" - No locks");
return;
}
for (DatabaseChangeLogLock lock : locks) {
out.println(" - " + lock.getLockedBy() + " at " +
DateFormat.getDateTimeInstance().format(lock.getLockGranted()));
}

out.println("NOTE: The lock time displayed is based on the database's configured time");
}

public void forceReleaseLocks() throws LiquibaseException {
Expand Down
Expand Up @@ -8,6 +8,7 @@
import liquibase.sql.Sql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.SqlGeneratorFactory;
import liquibase.statement.DatabaseFunction;
import liquibase.statement.core.LockDatabaseChangeLogStatement;
import liquibase.statement.core.UpdateStatement;
import liquibase.util.NetUtil;
Expand Down Expand Up @@ -44,9 +45,10 @@ public Sql[] generateSql(LockDatabaseChangeLogStatement statement, Database data
ObjectQuotingStrategy currentStrategy = database.getObjectQuotingStrategy();
database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY);
try {
String dateValue = database.getCurrentDateTimeFunction();
UpdateStatement updateStatement = new UpdateStatement(liquibaseCatalog, liquibaseSchema, database.getDatabaseChangeLogLockTableName());
updateStatement.addNewColumnValue("LOCKED", true);
updateStatement.addNewColumnValue("LOCKGRANTED", new Timestamp(new java.util.Date().getTime()));
updateStatement.addNewColumnValue("LOCKGRANTED", new DatabaseFunction(dateValue));
updateStatement.addNewColumnValue("LOCKEDBY", hostname + hostDescription + " (" + hostaddress + ")");
updateStatement.setWhereClause(database.escapeColumnName(liquibaseCatalog, liquibaseSchema, database.getDatabaseChangeLogTableName(), "ID") + " = 1 AND " + database.escapeColumnName(liquibaseCatalog, liquibaseSchema, database.getDatabaseChangeLogTableName(), "LOCKED") + " = "+ DataTypeFactory.getInstance().fromDescription("boolean", database).objectToSql(false, database));

Expand Down
Expand Up @@ -73,4 +73,17 @@ public void testOutputChangeLog() throws Exception {
assertTrue(true);
}

@Override
public void tearDown() throws Exception {
super.tearDown();
try {
String url = getDatabase().getConnection().getURL()
.replaceFirst("jdbc:sqlite:", ""); // remove the prefix of the URL jdbc:sqlite:C:\path\to\tmp\dir\liquibase.db
Scope.getCurrentScope().getLog(getClass()).info("Marking SQLite database as delete on exit: " + url);
// Want to delete the sqlite db on jvm exit so that future runs are not using stale data.
new File(url).deleteOnExit();
} catch (Exception e) {
Scope.getCurrentScope().getLog(getClass()).warning("Failed to mark SQLite database as delete on exit.", e);
}
}
}
Expand Up @@ -84,7 +84,7 @@
<changeSet id="7a" author="nvoxland">
<addColumn tableName="employee">
<column name="company_id" type="int">
<constraints nullable="true" foreignKeyName="fk_employee_company" references="employee(id)"/>
<!-- <constraints nullable="true" foreignKeyName="fk_employee_company" references="employee(id)"/>-->
</column>
</addColumn>
</changeSet>
Expand Down