Liquibase Command clearChecksum

The MD5 checksome serves as the unique identifier in Liquibase for differentiating multiple ChangeSet. Liquibase saves these MD5 checksome in DATABASECHANGELOG table as well for future reference.

Liquibase provides clearChecksumcommand which clearn all the MD5 checksome in the DATABASECHANGELOG table, once next database update happens, LIquibase will recalculate all the Checksum from ChangeSet and update the DATABASECHANGELOG table.

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
	<changeSet author="wesome" id="1697962298531-1">
		<createTable catalogName="appledb" tableName="apple">
			<column autoIncrement="true" name="apple_id" type="BIGINT">
				<constraints nullable="false" primaryKey="true" />
			</column>
			<column name="apple_name" type="VARCHAR(255)" />
			<column name="available" type="CHAR(1)" />
			<column defaultValueComputed="CURRENT_TIMESTAMP" name="current_date_time" type="datetime" />
		</createTable>
	</changeSet>
	<changeSet author="wesome" id="1697962298531-2">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_name" value="Macintosh" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="now()" />
		</insert>
	</changeSet>
	<changeSet author="wesome" id="1697962298531-3">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_name" value="Fuji" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="now()" />
		</insert>
	</changeSet>
</databaseChangeLog>

liquibase.properties (update changeLog File file format with SQL, XML, YAML, JSON as per changelog.mysql.)

changeLogFile=changelog.mysql.xml
liquibase.command.url:jdbc:mysql://localhost:3306/appleDb?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.username : root
liquibase.command.password : rootroot

to update the ChangeSet in database, execute the command

liquibase update

Liquibase will update the database with all ChangeSet in ChangeLog file and insert records corresponding of each ChangeSet in DATABASECHANGELOG table with MD5 checksome.

select * from appleDb.DATABASECHANGELOG;

to clear all the MD5 checksum from DATABASECHANGELOG table, execute the command.

liquibase clearChecksums

it will delete all MD5 checksum from DATABASECHANGELOG table, same can be verified by executing the command

select * from appleDb.DATABASECHANGELOG;

once Liquibase updates the database, it will recalculate all the MD5 checksums again. lets see with an example, update the changelog.mysql.xml file and insert a new ChangeSet as below

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
	<changeSet author="wesome" id="1697962298531-1">
		<createTable catalogName="appledb" tableName="apple">
			<column autoIncrement="true" name="apple_id" type="BIGINT">
				<constraints nullable="false" primaryKey="true" />
			</column>
			<column name="apple_name" type="VARCHAR(255)" />
			<column name="available" type="CHAR(1)" />
			<column defaultValueComputed="CURRENT_TIMESTAMP" name="current_date_time" type="datetime" />
		</createTable>
	</changeSet>
	<changeSet author="wesome" id="1697962298531-2">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_name" value="Macintosh" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="now()" />
		</insert>
	</changeSet>
	<changeSet author="wesome" id="1697962298531-3">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_name" value="Fuji" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="now()" />
		</insert>
	</changeSet>
	<changeSet author="wesome" id="1697962298531-4">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_name" value="Gala" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="now()" />
		</insert>
	</changeSet>
</databaseChangeLog>

execute the command

liquibase update

Liquibase will insert the new ChangeSet in database as well as update all the MD5 checksome, same can be verified by executing the command

select * from appleDb.DATABASECHANGELOG;

follow us on