generate-changelog
The generate-changelog
command creates a changelog file that has a sequence of changesets which describe how to re-create the current state of the database.
Uses
The generate-changelog
command is typically used when you want to capture the current state of a database, then apply those changes to any number of databases. This is typically only done when a project has an existing database, but hasn't used Liquibase before. See How to set up Liquibase with an Existing Project and Multiple Environments for more details.
Note: When using the update command to apply the changes in the changelog, Liquibase will not create a new database or schema. You must create them before applying the changelog to it.
Syntax
To generate a changelog:
- Configure the Liquibase properties file to include your driver, classpath, and URL for the database you want to capture.
- Open your CLI and run the following command:
Note: For more information on how to configure the Liquibase properties file, see the Create and Configure a liquibase.properties File topic. Instead of using a properties file, you can pass the necessary information from the command line.
liquibase generate-changelog --changelog-file=example-changelog.xml
Global arguments
Tip: For best results, specify all commands and parameters in the --kebab-case
format in the CLI. If your preference is camelCase, it also works in the CLI.
Attribute | Definition | Requirement |
---|---|---|
--license-key
|
Your Liquibase Pro license key |
Optional |
Command arguments
Attribute | Definition | Requirement |
---|---|---|
--url
|
The JDBC database connection URL. See Using JDBC URL in Liquibase. |
Required |
--author
|
Specifies the author for changesets in the generated changelog. |
Optional |
--changelog-file
|
Changelog file to write results |
Optional |
--contextFilter
|
Specifies the changeset contexts to match. Contexts are expressions you can add to changesets to control which changesets are executed in any particular migration run. |
Optional |
--data-output-directory=DIR
|
Specifies a directory to send the data output of the command as a CSV file. |
Optional |
--default-catalog-name
|
Name of the default catalog to use for the database connection |
Optional |
--default-schema-name
|
Name of the default schema to use for the database connection. If Tip: In Liquibase v4.23.0+, camelCase for Note: The syntax |
Optional |
--diff-types
|
Specifies the types of objects to compare. Includes a list of diff types in a changelog file expressed as a comma-separated list (without spaces): If null, default types are |
Optional |
--driver
|
The JDBC driver class |
Optional |
--driver-properties-file
|
The JDBC driver properties file |
Optional |
--exclude-objects
|
Objects to exclude from diff |
Optional |
--include-catalog=<true|false>
|
If |
Optional |
--include-objects
|
Objects to include in diff |
Optional |
--include-schema=<true|false>
|
If |
Optional |
--include-tablespace=<true|false>
|
Includes the tablespace of tables and indexes in a generated changesets if the value is |
Optional * |
--label-filter
|
Specifies the changeset labels to match. Labels are tags you can add to changesets to control which changeset will be executed in any migration run. |
Optional |
--output-schemas
|
Example: |
Optional |
--overwrite-output-file=<true|false>
|
Determines whether |
Optional |
--password
|
Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
--schemas=<name1, name2>
|
Specifies database schemas you want to include |
Optional |
--username
|
Username to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. |
Optional |
Note: The username
and password
attributes are not required for connections and systems which use alternate means of authentication. Also, you can specify database credentials as part of the url
attribute.
* --include-tablespace
only captures the tablespace if it was specified in the create table
statement.
Output
The generate-changelog
command generates a changelog that contains all your objects (represented as changesets) and places the file in the same directory where the command was ran.
The extension you provide determines the format of the changelog, so if you specify the filename as changelog.xml
, you will get an XML formatted changelog. However, if you specify the filename as changelog.yaml
, changelog.json
, or changelog.sql
, you will get changelogs formatted in YAML, JSON, or SQL, respectively.

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
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">
<changeSet author="diff-generated" id="1185214997195-1">
<createTable name="BONUS">
<column name="ENAME" type="VARCHAR2(10,0)"/>
<column name="JOB" type="VARCHAR2(9,0)"/>
<column name="SAL" type="NUMBER(22,0)"/>
<column name="COMM" type="NUMBER(22,0)"/>
</createTable>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-2">
<createTable name="DEPT">
<column name="DEPTNO" type="NUMBER(2,0)"/>
<column name="DNAME" type="VARCHAR2(14,0)"/>
<column name="LOC" type="VARCHAR2(13,0)"/>
</createTable>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-3">
<createTable name="EMP">
<column name="EMPNO" type="NUMBER(4,0)"/>
<column name="ENAME" type="VARCHAR2(10,0)"/>
<column name="JOB" type="VARCHAR2(9,0)"/>
<column name="MGR" type="NUMBER(4,0)"/>
<column name="HIREDATE" type="DATE(7,0)"/>
<column name="SAL" type="NUMBER(7,2)"/>
<column name="COMM" type="NUMBER(7,2)"/>
<column name="DEPTNO" type="NUMBER(2,0)"/>
</createTable>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-4">
<createTable name="SALGRADE">
<column name="GRADE" type="NUMBER(22,0)"/>
<column name="LOSAL" type="NUMBER(22,0)"/>
<column name="HISAL" type="NUMBER(22,0)"/>
</createTable>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-5">
<addForeignKeyConstraint baseColumnNames="DEPTNO"
baseTableName="DEPT" constraintName="FK_NAME"
referencedColumnNames="DEPTNO" referencedTableName="EMP"/>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-6">
<createIndex indexName="PK_DEPT" tableName="DEPT">
<column name="DEPTNO"/>
</createIndex>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-7">
<createIndex indexName="PK_EMP" tableName="EMP">
<column name="EMPNO"/>
</createIndex>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-8">
<addPrimaryKey columnNames="DEPTNO" tableName="DEPT"/>
</changeSet>
<changeSet author="diff-generated" id="1185214997195-9">
<addPrimaryKey columnNames="EMPNO" tableName="EMP"/>
</changeSet>
</databaseChangeLog>
Additional functionality with Liquibase Pro
While Liquibase Open Source stores all changesets in a changelog, Liquibase Pro creates a directory called Objects
and places the directory at the same level as your changelog. The Objects
directory contains a subdirectory for each of the following stored logic types:
- package
- packagebody
- function
- stored procedure
- trigger
- view
Note: Some database platforms may not support all of these stored logic types.
The generate-changelog
command will not create the Objects
directory if:
- You don't have a valid
ProKey
- There are no stored logic objects in the database
- The changelog file is written in formatted SQL (the
Objects
folder can only be created when generating XML, JSON or YAML changelogs) - The target database is not supported with the
generate-changelog
command and stored logic objects
If your database contains stored logic objects, you may have issues attempting to run the generate-changelog
command more than once, even with a new changelog name, because the stored logic files already exist in the Objects
directory.
To generate a newer version of the changelog file with stored logic objects based on the current database state, you need to delete, rename, or move the Objects
directory that was created by running the generate-changelog
command previously. Then, you can run the generate-changelog
command again.
Note: If there is a pre-existing Objects
directory that is not related to Liquibase, you need to delete, rename, or move it to run the generate-changelog
command.
If you want to track the history of stored logic objects, use the diff-changelog command. The diff-changelog
command structures stored logic files into timestamped directories every time you run the command.

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
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">
<changeSet author="Administrator (generated)" id="1571345362466-8">
<pro:createTrigger disabled="false" path="objects/trigger/TS_T_EXEMPLAR_SEQEXEMPLAR.sql" relativeToChangelogFile="true" tableName="T_EXEMPLAR" triggerName="TS_T_EXEMPLAR_SEQEXEMPLAR"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-12">
<createView fullDefinition="true" path="objects/view/OREDERS_VIEW.sql" relativeToChangelogFile="true" viewName="OREDERS_VIEW"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-14">
<createProcedure path="objects/storedprocedure/P_CUSTOMER_HAS_NUM_FILM.sql" procedureName="P_CUSTOMER_HAS_NUM_FILM" relativeToChangelogFile="true"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-20">
<pro:createFunction functionName="F_CUSTOMER_HAS_NUM_FILM" path="objects/function/F_CUSTOMER_HAS_NUM_FILM.sql" relativeToChangelogFile="true"/>
</changeSet>
</databaseChangeLog>
Related links
- Maven generateChangeLog
- Ant generateChangeLog