Liquibase Command snapshotReference

Liquibase provides a snapshot command that helps in capturing the current state of the target database, and if required it can also save the current state into the format provided in snapshotFormat attribute in the file name provided in outputFile attributes.

Liquibase also provides a snapshotReference command, which helps capture the source database's current state. and just like the snapshot command, if required it can also save the current state into the format provided in snapshotFormat attribute in the file name provided in outputFile attributes.

execute the below script into the database

create database appleDbSource;
use appleDbSource;
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());
insert into  apple (apple_name, available, current_date_time) values ("Fuji", 'Y',  now());
commit;
create database appleDbSource;
commit;

liquibase.properties (update changeLog File file format with SQL, XML, YAML, JSON as per changelog.mysql.)

liquibase.command.referenceUrl =jdbc:mysql://localhost:3306/appleDbSource?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.referenceUsername= root
liquibase.command.referencePassword= rootroot
snapshotFormat=json
outputFile=SourceDbSnapshot.json

To create a snapshot of the current database, execute the command

liquibase snapshotReference 

it will create a file named Snapshot.json, which will contain the current state of the database in JSON format

follow us on