changelogSyncSQL command

The changelogSyncSQL is a helper command that produces the raw SQL Liquibase would run when using the changelogSync command.

Uses

The changelogSyncSQL command is typically used when you want to inspect the SQL Liquibase will use to baseline a new database environment.

It is best practice to inspect any SQL that Liquibase would run when using the changelogSync command so you can review any changes the command would make to your database before running the command.

Running the changelogSyncSQL command

To run the changelogSyncSQL command, you can specify the driver, classpath, and URL in your liquibase.properties file. For more information, see Creating and configuring a liquibase.properties file. You can also specify these properties in your command line.

Then run the changelogSyncSQL command:

liquibase --changelogFile=mychangelog.postgresql.sql changelogSyncSQL

Note: Enter the name of the changelog that you want to use in place of mychangelog.postgresql.sql.

changelogSyncSQL global attributes

Attribute Definition Requirement
--changeLogFile The root changelog Required
--url The JDBC database connection URL Required
--username The database username Required*
--password The database password Required*
--outputFile* The attribute that specifies the file path to where the changelogSync SQL will be written Optional

*If not specified, the changelogSyncSQL output goes to STDOUT.

Note: The username and password attributes are not required for connections and systems which use alternate means of authentication.

changelogSyncSQL example output

When successful, the changelogSyncSQL command produces the following output:

####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 11:16:15 (version 4.4.1 #29 built at 2021-07-09 16:46+0000)
Liquibase Version: 4.4.1
Liquibase Pro 4.4.1 by Datical licensed to support until Wed Sep 22 23:59:59 CDT 2021
-- *********************************************************************
-- SQL to add all changesets to database history table
-- *********************************************************************
-- Change Log: changelog.postgresql.sql
-- Ran at: 7/20/21 11:16 AM
-- Against: postgres@jdbc:postgresql://example.net:5432/dev
-- Liquibase version: 4.4.1
-- *********************************************************************
SET SEARCH_PATH TO public;
SET SEARCH_PATH TO public;
-- Create Database Lock Table
CREATE TABLE public.databasechangeloglock (ID INTEGER NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP WITHOUT TIME ZONE, LOCKEDBY VARCHAR(255), CONSTRAINT databasechangeloglock_pkey PRIMARY KEY (ID));
-- Initialize Database Lock Table
DELETE FROM public.databasechangeloglock;
INSERT INTO public.databasechangeloglock (ID, LOCKED) VALUES (1, FALSE);
-- Lock Database
UPDATE public.databasechangeloglock SET LOCKED = TRUE, LOCKEDBY = 'support.lan (192.168.86.134)', LOCKGRANTED = '2021-07-20 11:16:17.947' WHERE ID = 1 AND LOCKED = FALSE;
SET SEARCH_PATH TO public;
-- Create Database Change Log Table
CREATE TABLE public.databasechangelog (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED TIMESTAMP WITHOUT TIME ZONE NOT NULL, ORDEREXECUTED INTEGER NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10));
SET SEARCH_PATH TO public;
SET SEARCH_PATH TO public;
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('45555-createtablecontacts', 'SteveZ', 'changelog.postgresql.sql', NOW(), 1, '8:762f4f2f9b31cb411865bace78aa42b3', 'sql', '', 'EXECUTED', NULL, NULL, '4.4.1', '6797778392');
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('45556-createtableactor', 'SteveZ', 'changelog.postgresql.sql', NOW(), 2, '8:0e322f6cc1e214c77d91dad9188bee1e', 'sql', '', 'EXECUTED', NULL, NULL, '4.4.1', '6797778392');
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('45556-altertableactor', 'MikeO', 'changelog.postgresql.sql', NOW(), 3, '8:326c51cf9fcb314bf1e9a431855283e7', 'sql', '', 'EXECUTED', NULL, NULL, '4.4.1', '6797778392');
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('45678-createtablecolors', 'AmyS', 'changelog.postgresql.sql', NOW(), 4, '8:8fca28e33e361413b01ff002177024d4', 'sql', '', 'EXECUTED', NULL, NULL, '4.4.1', '6797778392');
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('45679-insertcolors', 'BenG', 'changelog.postgresql.sql', NOW(), 5, '8:0ffb494fbca85edc2eb31920c725f850', 'sql', '', 'EXECUTED', '(dev,test or prod)', 'v.0.1,v.1.1', '4.4.1', '6797778392');
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('45679-createfunction_get_film_count', 'SteveZ', 'changelog.postgresql.sql', NOW(), 6, '8:7eaa310a5ef2033d93ba3bfaee351810', 'sql', '', 'EXECUTED', NULL, NULL, '4.4.1', '6797778392');
- Release Database Lock
SET SEARCH_PATH TO public;
UPDATE public.databasechangeloglock SET LOCKED = FALSE, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;
SET SEARCH_PATH TO public;
Liquibase command 'changelogSyncSql' was executed successfully.