setDropFirst(true) still broken on empty database

Description

This is basically issue which claims to fix the issue, but it still exists.

In my end-to-end tests, I want to ensure that the database has been cleaned before priming. So, I am using the setDropFirst(true) method to tell liquibase to drop the schemas before priming. This works if the schema has been previously populated. However, it does not work when the schema is empty. This has been a issue for several versions of liquibase.

Below is the liquibase log that is produced:

Connected to jsruser@jsr-iaas-20.xxx.com@jdbc:mysql://lab-dev-db1/jsrinteg?useUnicode=true
Setting auto commit to false from true
Computed checksum for 1423765232048 as 5161db72467de2255ee29d5f065e9dc8
Create Database Lock Table
Executing EXECUTE database command: CREATE TABLE jsrinteg.PERSON_DBCHANGELOG (ID INT NOT NULL, LOCKED BIT(1) NOT NULL, LOCKGRANTED datetime NULL, LOCKEDBY VARCHAR(255) NULL, CONSTRAINT PK_PERSON_DBCHANGELOG PRIMARY KEY (ID))
Created database lock table with name: jsrinteg.PERSON_DBCHANGELOG
Executing QUERY database command: select count from jsrinteg.PERSON_DBCHANGELOG
Initialize Database Lock Table
Executing EXECUTE database command: DELETE FROM jsrinteg.PERSON_DBCHANGELOG
Executing EXECUTE database command: INSERT INTO jsrinteg.PERSON_DBCHANGELOG (ID, LOCKED) VALUES (1, 0)
Executing QUERY database command: SELECT LOCKED FROM jsrinteg.PERSON_DBCHANGELOG WHERE ID=1
Lock Database
Executing UPDATE database command: UPDATE jsrinteg.PERSON_DBCHANGELOG SET LOCKED = 1, LOCKEDBY = 'JSR-IAAS-20 (10.102.3.125)', LOCKGRANTED = '2015-02-12 13:21:30.379' WHERE ID = 1 AND LOCKED = 0
Successfully acquired change log lock
Dropping Database Objects in schema: jsrinteg.jsrinteg
Create Database Change Log Table
Creating database history table with name: jsrinteg.PERSON_DBCHANGELOGLOCK
Executing EXECUTE database command: CREATE TABLE jsrinteg.PERSON_DBCHANGELOGLOCK (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED datetime NOT NULL, ORDEREXECUTED INT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35) NULL, DESCRIPTION VARCHAR(255) NULL, COMMENTS VARCHAR(255) NULL, TAG VARCHAR(255) NULL, LIQUIBASE VARCHAR(20) NULL)
Executing QUERY database command: select count from jsrinteg.PERSON_DBCHANGELOG
Database snapshot generated in 110 ms. Snapshot includes: [class liquibase.structure.core.View, class liquibase.structure.core.Catalog, class liquibase.structure.core.Schema, class liquibase.structure.core.Sequence, class liquibase.structure.core.Table, class liquibase.structure.core.StoredProcedure, class liquibase.structure.core.Column]
MissingObjectChangeGenerator type order: liquibase.structure.core.Catalog liquibase.structure.core.Schema liquibase.structure.core.Sequence liquibase.structure.core.StoredProcedure liquibase.structure.core.Table liquibase.structure.core.Column liquibase.structure.core.PrimaryKey liquibase.structure.core.UniqueConstraint liquibase.structure.core.ForeignKey liquibase.structure.core.Index liquibase.structure.core.View
UnexpectedObjectChangeGenerator type order: liquibase.structure.core.Catalog liquibase.structure.core.ForeignKey liquibase.structure.core.Schema liquibase.structure.core.StoredProcedure liquibase.structure.core.UniqueConstraint liquibase.structure.core.View liquibase.structure.core.Table liquibase.structure.core.PrimaryKey liquibase.structure.core.Column liquibase.structure.core.Index liquibase.structure.core.Sequence
ChangedObjectChangeGenerator type order: liquibase.structure.core.Catalog liquibase.structure.core.ForeignKey liquibase.structure.core.Schema liquibase.structure.core.Sequence liquibase.structure.core.StoredProcedure liquibase.structure.core.Table liquibase.structure.core.Column liquibase.structure.core.PrimaryKey liquibase.structure.core.Index liquibase.structure.core.UniqueConstraint liquibase.structure.core.View
ChangeSet to Remove Database Objects generated in 48 ms.
Executing QUERY database command: SELECT @@FOREIGN_KEY_CHECKS
Executing EXECUTE database command: SET FOREIGN_KEY_CHECKS=0
Executing EXECUTE database command: SET FOREIGN_KEY_CHECKS=1
Executing EXECUTE database command: DROP TABLEjsrinteg.PERSON_DBCHANGELOGLOCK
Executing EXECUTE database command: DROP TABLEjsrinteg.PERSON_DBCHANGELOG
Successfully released change log lock
Executing QUERY database command: select count from jsrinteg.PERSON_DBCHANGELOG

I started to trace through the liquibase code and the problem seems to be with the StandardLockService class. As per the logs, it is creating the dbchangelog and dbchangeloglock tables (which in my opinion it shouldn't bother with if DropFirst is true) and then deleting them when it drops the schema. The problem is that the StandardLockService.hasDatabaseChangeLogLockTable flag is not cleared when the schema is dropped. Since the lock service still thinks that the changelog tables are there, we get the SQL exception.

Environment

SpringLiquibase
MySQL

Reporter

John Rowland

Fix versions

Affects versions

Priority

Major
Configure