ChangeLog
file list all the changes in the Database
. This ledger helps Liquibase
to understand the current status of the Database
and execute changes that need to be applied.
ChangeLog
file divides the individual small change into ChangeSet
, and each Database
operation is stored sequentially in ChangeSet
. For example, Database
creation is 1 change set and table
creation is another ChangeSet
.
It is a best practice to add only one Change Type per changeset.
A complex Database
schema can be subdivided into multiple individuals ChangeLog
files. ChangeLog file allows
preconditions
, contexts
, labels
, and many other attributes.
Liquibase
allows to pass the ChangeLog
file dynamically with --changelog-file
argument in the command line (CLI)
, or else the ChangeLog
file can be set as JAVA_OPTS
in Environment Variable.
ChangeLog file format
Liquibase supports ChangeLog files in native SQL format or platform-agnostic XML, YAML, or JSON formats. it determines the format by the file extension. ChangeLog can include another ChangeLog file or include All multiple small ChangeLog files from a folder in XML, YAML, or JSON formats only SQL doesn't support file inclusion.
changelog.mysql.sql
-- liquibase formatted sql
-- changeset wesome:1692352309572-1
CREATE TABLE apple (apple_id BIGINT NOT NULL, apple_name VARCHAR(255) NULL, CONSTRAINT PK_APPLE PRIMARY KEY (apple_id));
changelog.mysql.yaml
databaseChangeLog:
- changeSet:
id: 1692352255676-1
author: wesome (generated)
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
primaryKey: true
name: apple_id
type: BIGINT
- column:
name: apple_name
type: VARCHAR(255)
tableName: apple
changelog.mysql.json
{
"databaseChangeLog": [
{
"changeSet": {
"id": "1692352264594-1",
"author": "wesome (generated)",
"changes": [
{
"createTable": {
"columns": [
{
"column": {
"constraints": {
"nullable": false,
"primaryKey": true
},
"name": "apple_id",
"type": "BIGINT"
}
},
{
"column": {
"name": "apple_name",
"type": "VARCHAR(255)"
}
}
],
"tableName": "apple"
}
}
]
}
}
]
}
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">
<changeSet author="wesome (generated)" id="1692352246983-1">
<createTable tableName="apple">
<column name="apple_id" type="BIGINT">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="apple_name" type="VARCHAR(255)"/>
</createTable>
</changeSet>
</databaseChangeLog>
Liquibase supports the use of multiple different changelog file formats at a time.
The ChangeLog
file name is stored in the liquibase.properties
file. Liquibase migrator
detects the ChangeLog
file format from the file extension.
It checks for global preconditions
first, then includes all ChangeLog
files specified with the include
tag. run each change set and store the executed changes in DATABASECHANGELOG
table.