Liquibase
supports SQL
, JSON
, YAML
, and XML
format for ChangeLog file.
SQL
file should be Liquibase formatted SQL
otherwise it will not run. Liquibase
provides modifyChangeSets
ChangeType that allows to execution of native SQL using native executer such as PSQL
, SQLPlus
, or SQLCMD
as well.
Some of the native executer provided by Liquibase
are
Executor | Used for |
---|---|
jdbc | Default value |
mongosh | Executor for MongoDB |
psql | Executor for PostgreSQL |
sqlplus | Executor for Oracle |
sqlcmd | Executor for MSSQL Server |
<?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="1692446190573-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="apple_taste" type="VARCHAR(255)" />
<column defaultValueComputed="CURRENT_TIMESTAMP" name="current_date_time" type="datetime" />
</createTable>
</changeSet>
<modifyChangeSets runWith="jdbc">
<include file="createTable.sql" />
</modifyChangeSets>
</databaseChangeLog>
insertData.sql
INSERT INTO appleDb.apple (apple_name, apple_taste, current_date_time) VALUES ('Macintosh','Sweet','2023-09-23 19:06:12'), ('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