Liquibase Command history

Liquibase provides an update command, which executes all the ChangeSets in a ChangeLog file. To verify the executed ChangeSets, Liquibase provides a history command that lets the DBA inspect the history of all the ChangeSets to ensure they have been executed successfully.

The history command will list all the deployed ChangeSets along with its deploymentId

<?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="shriksha (generated)" 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)">
				<constraints unique="true" />
			</column>
			<column name="available" type="CHAR(1)" />
			<column defaultValueComputed="CURRENT_TIMESTAMP" name="current_date_time" type="datetime" />
		</createTable>
	</changeSet>
	<changeSet author="shriksha (generated)" id="1697962298531-2">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_id" valueNumeric="1" />
			<column name="apple_name" value="Macintosh" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="2023-10-22T13:40:18" />
		</insert>
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_id" valueNumeric="2" />
			<column name="apple_name" value="Fuji" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="2023-10-22T13:40:19" />
		</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

execute the command

liquibase update

It will execute the ChangeSets and update the database accordingly, to validate the history of execution, run the command

liquibase history

Save Liquibase History Output into File

By default the output of history command will be written to STDOUT, but if required Liquibase allows to save the output of history command into a file.

<?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="shriksha (generated)" 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)">
				<constraints unique="true" />
			</column>
			<column name="available" type="CHAR(1)" />
			<column defaultValueComputed="CURRENT_TIMESTAMP" name="current_date_time" type="datetime" />
		</createTable>
	</changeSet>
	<changeSet author="shriksha (generated)" id="1697962298531-2">
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_id" valueNumeric="1" />
			<column name="apple_name" value="Macintosh" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="2023-10-22T13:40:18" />
		</insert>
		<insert catalogName="appledb" tableName="apple">
			<column name="apple_id" valueNumeric="2" />
			<column name="apple_name" value="Fuji" />
			<column name="available" value="Y" />
			<column name="current_date_time" valueDate="2023-10-22T13:40:19" />
		</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
outputFile=History.text
overwriteOutputFile=true

execute the command

liquibase update

It will execute the ChangeSets and update the database accordingly, to validate the history of execution, run the command

liquibase history

follow us on