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

DATABASECHANGELOGLOCK created multiple times in updateSQL mode #2295

Closed
zederisch opened this issue Dec 23, 2021 · 3 comments · Fixed by #2335
Closed

DATABASECHANGELOGLOCK created multiple times in updateSQL mode #2295

zederisch opened this issue Dec 23, 2021 · 3 comments · Fixed by #2335

Comments

@zederisch
Copy link

Environment
Liquibase Version: 4.6.2
Database Vendor & Version: Microsoft SQL Server 15.0.2080
Operating System Type & Version: Windows 10 Enterprise 21H1

Description
When running hte Liquibase configuration against a clean database in updateSQL to create a full database model deployment script, the "CREATE TABLE DATABASECHANGELOGLOCK" is generated in total 20 times. This only happens since 4.6.2, with 4.6.1 everything was fine regarding this issue.

Steps to reproduce
Liquibase configuration:
databaseChangeLog:

  • changeSet:
    id: createTable-1
    author: test
    changes:
    • createTable:
      tableName: table1
      columns:
      • column:
        name: test
        type: int

Batch file used for compiling:
@echo OFF

CALL runLiquibase.bat ^
--defaultsFile=./test_sqlserver.properties ^
--changeLogFile=./test.yml ^
--outputFile=./test.sql ^
--logLevel=ERROR ^
updateSQL

PAUSE

Properties file structure:
url: jdbc:sqlserver://localhost:1433;databaseName=
username:
password:
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath: /mssql-jdbc-9.4.0.jre8.jar
outputDefaultCatalog: false
liquibase.hub.mode=off

Result:
-- Create Database Lock Table
CREATE TABLE DATABASECHANGELOGLOCK (ID int NOT NULL, LOCKED bit NOT NULL, LOCKGRANTED datetime2(3), LOCKEDBY nvarchar(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))
GO

-- Initialize Database Lock Table
DELETE FROM DATABASECHANGELOGLOCK
GO

INSERT INTO DATABASECHANGELOGLOCK (ID, LOCKED) VALUES (1, 0)
GO

-- Create Database Lock Table
CREATE TABLE DATABASECHANGELOGLOCK (ID int NOT NULL, LOCKED bit NOT NULL, LOCKGRANTED datetime2(3), LOCKEDBY nvarchar(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))
GO

-- Initialize Database Lock Table
DELETE FROM DATABASECHANGELOGLOCK
GO

INSERT INTO DATABASECHANGELOGLOCK (ID, LOCKED) VALUES (1, 0)
GO

[...]

You can find the used test setup here:
test.zip

@Axinet
Copy link

Axinet commented Dec 23, 2021

Yes, I also fall in this issue.
This bad behavior has been introduced with #2198
which was planned to fix #2083

I found the issue while using liquibase.Liquibase#update(liquibase.Contexts, liquibase.LabelExpression, java.io.Writer, boolean) (update method with output send to provided writer).

Issue suggested creating table if not exist, but current codebase just tries to create table 10 times (from two different places, which results in total of 20 create statements), which results in errors when executing such script on the real database.

Also the value for forceRecheck is set to hardcoded true and even cannot be set in configuration to false, to not execute this rechecks (but I didn't check if such case script will end with single or doubled CREATE TABLE DATABASECHANGELOGLOCK).

@kataggart
Copy link
Contributor

Thanks @zederisch and @Axinet for the details you provided here. We will review this and move forward towards resolution. Especially appreciate the inclusion of the test set up details as well as the links to the related previous issues/PRs.

Hope to see both of you over at https://forum.liquibase.org/ -- I am sure some newer community members could benefit from your expertise.

@nvoxland
Copy link
Contributor

nvoxland commented Jan 6, 2022

This should be fixed in #2335

@nvoxland nvoxland moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Jan 7, 2022
Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Jan 24, 2022
@nvoxland nvoxland added this to the v4.8.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
4 participants