Removing Run Status
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/liquibase/ext/clickhouse/sqlgenerator/RemoveChangeSetRanStatusClickHouse.java
- src/main/java/liquibase/ext/clickhouse/database/ClickHouseDatabase.java
- src/main/java/liquibase/ext/clickhouse/params/ParamsLoader.java
- src/main/java/liquibase/ext/clickhouse/sqlgenerator/SqlGeneratorUtil.java
- src/main/java/liquibase/ext/clickhouse/sqlgenerator/CreateDatabaseChangeLogTableClickHouse.java
- src/main/java/liquibase/ext/clickhouse/params/ClusterConfig.java
Removing Run Status refers to the mechanism within the Liquibase ClickHouse extension that deletes the execution record of a specific changeset from the database's tracking table. This process is essential for rollback operations or for resetting the state of a changeset so it can be executed again.
In ClickHouse, this is implemented using the ALTER TABLE ... DELETE mutation syntax, which differs significantly from standard SQL DELETE statements due to ClickHouse's eventual consistency and mutation handling.
Sources: RemoveChangeSetRanStatusClickHouse.java:44-63, README.md:14-16
Architecture and Implementation
The removal logic is encapsulated in the RemoveChangeSetRanStatusClickHouse class. This class extends the standard Liquibase RemoveChangeSetRanStatusGenerator but overrides the SQL generation to accommodate ClickHouse-specific syntax and cluster configurations.
Key Components
- RemoveChangeSetRanStatusClickHouse: The primary class responsible for generating the
ALTER TABLE ... DELETEstatement. It identifies the target changeset using a composite key ofID,AUTHOR, andFILENAME. - SqlGeneratorUtil: A utility class used to append cluster-specific clauses (like
ON CLUSTER) to the SQL if the extension is running in cluster mode. - ParamsLoader: Loads configuration details (e.g., cluster name) to ensure the mutation is applied across the entire ClickHouse cluster if necessary.
Sources: RemoveChangeSetRanStatusClickHouse.java:34-42, SqlGeneratorUtil.java:44-52, ParamsLoader.java:73-75
Removal Flow Diagram
The following diagram illustrates how the extension generates the removal command and determines whether to include cluster-wide execution clauses.
SQL Mutation Logic
ClickHouse handles the removal of rows via asynchronous mutations. To ensure Liquibase waits for the deletion to complete before proceeding, the generated SQL explicitly sets mutations_sync = 1.
Command Structure
The generated SQL follows this structure:
ALTER TABLE `schema`.DATABASECHANGELOG
[ON CLUSTER 'name']
DELETE WHERE ID = 'id' AND AUTHOR = 'author' AND FILENAME = 'file'
SETTINGS mutations_sync = 1
Data Targeted for Removal
The removal process targets specific fields in the DATABASECHANGELOG table to ensure precision.
| Field | ClickHouse Type | Description |
|---|---|---|
| ID | String | The unique identifier of the changeset. |
| AUTHOR | String | The author defined in the changeset. |
| FILENAME | String | The path/name of the changelog file containing the changeset. |
Sources: RemoveChangeSetRanStatusClickHouse.java:53-61, CreateDatabaseChangeLogTableClickHouse.java:53-56
Cluster Support
When the extension is configured for cluster mode via the liquibaseClickhouse.conf file, the removal of a run status is propagated across the cluster.
Cluster Logic Sequence
This sequence shows the interaction between the generator and the configuration parameters.
Summary
Removing run status in the Liquibase ClickHouse extension ensures that the tracking table reflects the current desired state of the database schema. By leveraging ClickHouse mutations and synchronizing them, the extension provides a reliable way to roll back or retry changeset executions, even in distributed cluster environments.
Sources: RemoveChangeSetRanStatusClickHouse.java:50-63, README.md:14-25