The generateChangeLog
command provided by Liquibase
is one of the most used commands, it captures the current state
of an existing Database
. it generates a ChangeLog
file that contains all the ChangeSets
required to recreate the current state
of the database
. Then this newly generated ChangeLog
file can be applied to any number and any type of database
if Liquibase
supports it.
execute the below query in the database
create database appleDbSource;
use appleDb;
create table apple (apple_id bigint not null AUTO_INCREMENT , apple_name varchar(255), available CHAR(1), current_date_time datetime default now(), primary key (apple_id), CONSTRAINT uqniue_apple_name UNIQUE (apple_name)) engine=InnoDB;
insert into apple (apple_name, available, current_date_time) values ("Macintosh", 'Y', now());
commit;
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/appleDbSource?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.username : root
liquibase.command.password : rootroot
execute command
liquibase generateChangeLog
It will create a new ChangeLog
file with the name changelog.mysql.xml
, In order to recreate the same database state
to a new database
, update the connection URL
changeLogFile=changelog.mysql.xml
liquibase.command.url:jdbc:mysql://localhost:3306/appleDbTarget?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.username : root
liquibase.command.password : rootroot
execute the command
liquibase update
it will execute all DDL
and DML
commands of each ChangeSet
mentioned in the ChangeLog
file.
Filter generateChangeLog
by Default Liquibase
command generateChangeLog
will create ChangeLog
for tables
, views
, columns
, indexes
, foreignkeys
, primarykeys
and uniqueconstraints
. but if required, Liquibase
provides an diffTypes
attributes to filter
and specify the type of object
.
execute the below query in the database
create database appleDbSource;
use appleDb;
create table apple (apple_id bigint not null AUTO_INCREMENT , apple_name varchar(255), available CHAR(1), current_date_time datetime default now(), primary key (apple_id), CONSTRAINT uqniue_apple_name UNIQUE (apple_name)) engine=InnoDB;
insert into apple (apple_name, available, current_date_time) values ("Macintosh", 'Y', now());
commit;
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/appleDbSource?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.username : root
liquibase.command.password : rootroot
diffTypes:catalogs,tables,functions,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints,data,storedprocedures,triggers,sequences,databasepackage,databasepackagebody
execute the command
liquibase generateChangeLog
it will create a new ChangeLog
file with the name changelog.mysql.xml
for all diffType
mentioned in liquibase.properties
file