From ba5f4977bf857d3c5a77f06c7deb104255a8268c Mon Sep 17 00:00:00 2001 From: Gustav Larson Date: Tue, 6 Dec 2022 10:17:07 +0100 Subject: [PATCH] Add mutations_sync setting to ALTER statements Since Liquibase is checking the number of affected rows the query needs to run synchronously to avoid exceptions in the log. --- .../sqlgenerator/LockDatabaseChangeLogClickHouse.java | 3 ++- .../sqlgenerator/RemoveChangeSetRanStatusClickHouse.java | 3 ++- .../sqlgenerator/UnlockDatabaseChangelogClickHouse.java | 3 ++- .../sqlgenerator/UpdateChangeSetChecksumClickHouse.java | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/LockDatabaseChangeLogClickHouse.java b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/LockDatabaseChangeLogClickHouse.java index ed1bb0d..eb692d4 100644 --- a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/LockDatabaseChangeLogClickHouse.java +++ b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/LockDatabaseChangeLogClickHouse.java @@ -53,7 +53,8 @@ public Sql[] generateSql( String.format( "ALTER TABLE %s.%s " + SqlGeneratorUtil.generateSqlOnClusterClause(properties) - + "UPDATE LOCKED = 1,LOCKEDBY = '%s',LOCKGRANTED = %s WHERE ID = 1 AND LOCKED = 0", + + "UPDATE LOCKED = 1,LOCKEDBY = '%s',LOCKGRANTED = %s WHERE ID = 1 AND LOCKED = 0" + + " SETTINGS mutations_sync = 1", database.getDefaultSchemaName(), database.getDatabaseChangeLogLockTableName(), host, diff --git a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/RemoveChangeSetRanStatusClickHouse.java b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/RemoveChangeSetRanStatusClickHouse.java index e88cd90..ab3402b 100644 --- a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/RemoveChangeSetRanStatusClickHouse.java +++ b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/RemoveChangeSetRanStatusClickHouse.java @@ -54,7 +54,8 @@ public Sql[] generateSql( String.format( "ALTER TABLE %s.%s " + SqlGeneratorUtil.generateSqlOnClusterClause(properties) - + "DELETE WHERE ID = '%s' AND AUTHOR = '%s' AND FILENAME = '%s'", + + "DELETE WHERE ID = '%s' AND AUTHOR = '%s' AND FILENAME = '%s'" + + " SETTINGS mutations_sync = 1", database.getDefaultSchemaName(), database.getDatabaseChangeLogTableName(), changeSet.getId(), diff --git a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UnlockDatabaseChangelogClickHouse.java b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UnlockDatabaseChangelogClickHouse.java index 2820c5b..28985a3 100644 --- a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UnlockDatabaseChangelogClickHouse.java +++ b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UnlockDatabaseChangelogClickHouse.java @@ -52,7 +52,8 @@ public Sql[] generateSql( String.format( "ALTER TABLE %s.%s " + SqlGeneratorUtil.generateSqlOnClusterClause(properties) - + "UPDATE LOCKED = 0,LOCKEDBY = null, LOCKGRANTED = null WHERE ID = 1 AND LOCKED = 1", + + "UPDATE LOCKED = 0,LOCKEDBY = null, LOCKGRANTED = null WHERE ID = 1 AND LOCKED = 1" + + " SETTINGS mutations_sync = 1", database.getDefaultSchemaName(), database.getDatabaseChangeLogLockTableName()); diff --git a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UpdateChangeSetChecksumClickHouse.java b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UpdateChangeSetChecksumClickHouse.java index 17fe53b..b23d48a 100644 --- a/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UpdateChangeSetChecksumClickHouse.java +++ b/src/main/java/liquibase/ext/clickhouse/sqlgenerator/UpdateChangeSetChecksumClickHouse.java @@ -54,7 +54,8 @@ public Sql[] generateSql( String.format( "ALTER TABLE %s.%s " + SqlGeneratorUtil.generateSqlOnClusterClause(properties) - + "UPDATE MD5SUM = '%s' WHERE ID = '%s' AND AUTHOR = '%s' AND FILENAME = '%s'", + + "UPDATE MD5SUM = '%s' WHERE ID = '%s' AND AUTHOR = '%s' AND FILENAME = '%s'" + + " SETTINGS mutations_sync = 1", database.getDefaultSchemaName(), database.getDatabaseChangeLogTableName(), changeSet.generateCheckSum().toString(),