Liquibase Change Types include

The Liqubase provides ChangeLog file which contains multiple ChangeSets, and each ChangeSet is a database command, for small database changes, keeping all ChangeSet in a single ChangeLog file makes more sense, but as the ChangeSet increases, it's better to segregate them into multiple Changelog files.

ChangeLog segregation can be on any basis such as based on features, releases, or other logical segregation.

 changelog.mysql.xml

<?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">
	<include file=".\changelog\createTable\CreateTable.sql" />
	<include file=".\changelog\appleId1\appleId1.sql" />
	<include file=".\changelog\appleId2\appleId2.sql" />
</databaseChangeLog>

.\changelog\createTable\CreateTable.sql

-- liquibase formatted sql

-- changeset shriksha:1695477159989-1
DROP TABLE IF EXISTS appledb.apple;
CREATE TABLE appledb.apple (apple_id BIGINT AUTO_INCREMENT NOT NULL, apple_name VARCHAR(255) NULL, apple_taste VARCHAR(255) NULL, current_date_time datetime DEFAULT NOW() NULL, CONSTRAINT PK_APPLE PRIMARY KEY (apple_id));

.\changelog\appleId1\appleId1.sql

-- liquibase formatted sql

-- changeset shriksha:1695477159989-2
INSERT INTO `apple` VALUES (1,'Macintosh','Sweet','2023-09-23 19:06:12');

.\changelog\appleId2\appleId2.sql

-- liquibase formatted sql

-- changeset shriksha:1695477159989-2
INSERT INTO `apple` VALUES (2,'Fuji','Salty','2023-09-23 19:06:12');

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

Run command liquibase update

The table has been created and records are inserted, the same can be confirmed by running the command.

SELECT * FROM appleDb.apple;
 

follow us on