Maven generateChangeLog
generateChangeLog
creates a changelog file that has a sequence of changesets which describe how to re-create the current state of the database.
Uses
generateChangeLog
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
goal 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.
Maven configuration
Liquibase Maven can be configured in multiple ways. One way is to define your Liquibase configuration properties in your pom.xml
file. To configure your pom.xml
file, refer to Configuring Liquibase Attributes in your Maven POM File. If your pom.xml
does not reference a liquibase.properties
file, include <changeLogFile> specify your changelog file here</changeLogFile>
to the pom.xml
.
Also, before running the generateChangeLog
goal, add <outputChangeLogFile>specify the changelog file name you want to generate here</outputChangeLogFile>
to your pom.xml
file.
Running the generateChangeLog
Maven goal
Running the generateChangeLog
goal requires a Maven project to be implemented.
To run the goal, type the following in your command prompt:
mvn liquibase:generateChangeLog

The generateChangeLog
goal generates a changelog that contains all your objects (represented as changesets) and places the file in the same directory where the goal was ran.
The extension provided 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
or changelog.json
or changelog.postgresql.sql
you will get changelogs formatted in YAML or JSON or SQL, respectively.
Note: When generating an SQL formatted changelog, you must specify the short name of the targeted database type as part of the filename (as shown in the previous sentence). To find or check your database’s short name, see Supported Databases.
When successful, the generateChangeLog
Maven goal produces the following output:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.example:liquibase-project >--------------------
[INFO] Building liquibase-project 05XII19
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:4.1.1:generateChangeLog (default-cli) @ liquibase-project ---
[INFO] ------------------------------------------------------------------------
[INFO] Successfully installed license from Base64 string starting with 'ABwwGgQUvH' (property liquibaseProLicenseKey).
[INFO] Liquibase Pro 4.1.1 by Datical licensed to support until Wed Sep 22 23:59:59 CDT 2021
[INFO] Liquibase Pro 4.1.1 by Datical licensed to support until Wed Sep 22 23:59:59 CDT 2021
[INFO] ####################################################
## _ _ _ _ ##
## | | (_) (_) | ##
## | | _ __ _ _ _ _| |__ __ _ ___ ___ ##
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ##
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ##
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ##
## | | ##
## |_| ##
## ##
## Get documentation at docs.liquibase.com ##
## Get certified courses at learn.liquibase.com ##
## Get advanced features and support at ##
## liquibase.com/support ##
## ##
####################################################
Starting Liquibase at 10:35:51 (version 4.1.1 #10 built at 2020-10-12 19:24+0000)
[INFO] Parsing Liquibase Properties File local.liquibase.properties for changeLog parameters
[INFO] Executing on Database: jdbc:oracle:thin:@localhost:1521/ORCL
[INFO] Generating Change Log from database MVN_UAT @ jdbc:oracle:thin:@localhost:1521/ORCL (Default Schema: MVN_UAT)
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed
[INFO] changeSets count: 1
[INFO] dbchangelog.xml does not exist, creating and adding 1 changesets.
[INFO] Output written to Change Log file, dbchangelog.xml
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.373 s
[INFO] Finished at: 2020-11-25T10:35:57-06:00
[INFO] ------------------------------------------------------------------------

When using Liquibase Community, the Maven example shown earlier will generate an XML file that might look like the following:
<?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: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-4.1.1.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.1.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>

Liquibase Pro produces a similar changelog file to the one that is produced by Liquibase Community; however, it also produces the additional detail and files and supports specific stored logic information. The Liquibase Pro-supported stored logic types are:
- package
- packagebody
- function
- stored procedure
- trigger
- view
Note: Not all database platforms support all these types.
If you choose a SQL formatted changelog, the information about these stored logic types will be placed directly in the changelog file.
If you choose an XML, YAML, or JSON changelog format, the information about these types will be stored in a directory called Objects
, which will be placed at the same level as your changelog. The Objects
directory contains a subdirectory for each of the listed stored logic types that contain the definition information for any items of that type found in the database. The generated changelog file will contain references to that definition information. The following example illustrates an XML formatted changelog showing such references:
<?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: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-4.1.1.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>
generateChangeLog
optional Maven configuration attributes
Attribute | Definition |
---|---|
liquibase.changeSetAuthor | Specifies the author for changesets in the generated changelog. |
liquibase.changeSetContext | Specifies the execution context to be used for changesets in the generated changelog, which can be "," separated if there are multiple contexts. |
liquibase.changelogCatalogName | Specifies the catalog Liquibase will use to create your changelog tables. |
liquibase.changelogSchemaName | Specifies the schema Liquibase will use to create your changelog tables. |
liquibase.clearCheckSums [boolean] | Forces checksums to be cleared from the DATABASECHANGELOG table. Default value is: false. |
liquibase.contexts | Specifies which contexts Liquibase will execute, which can be separated by a comma if multiple contexts are required. If a context is not specified, then all contexts will be executed. |
liquibase.dataDir | Specifies the directory where insert statement CSV files will be kept. |
liquibase.databaseChangeLogLockTableName | Specifies the table name to use for the DATABASECHANGELOGLOCK table. |
liquibase.databaseChangeLogTableName | Specifies the table name to use for the DATABASECHANGELOG table. |
liquibase.databaseClass | Specifies the database object class. |
liquibase.defaultCatalogName | Specifies the default catalog name to use for the database connection. |
liquibase.defaultSchemaName | Specifies the default schema name to use for the database connection. |
liquibase.diffExcludeObjects | Specifies objects to be excluded from the changelog. Example filters: "table_name", "table:main_.*", "column:*._lock, table:primary.*". |
liquibase.diffIncludeObjects | Specifies objects to be included in the changelog. Example filters: "table_name", "table:main_.*", "column:*._lock, table:primary.*". |
liquibase.diffTypes |
Specifies the list of diff types to include in the changelog expressed as a comma-separated list from:
If this is null, then the default types will be:
|
liquibase.driver | Specifies the driver class name to use for the database connection. |
driverPropertiesFile | Specifies the location of a JDBC connection properties file which contains properties the driver will use. |
liquibase.emptyPassword [boolean] | Deprecated. Use an empty or null value for the password instead. Default value is: false. |
expressionVariables | Specifies a map-based collection of changelog properties to apply. |
expressionVars | Specifies a property-based collection of changelog properties to apply. |
liquibase.includeArtifact [boolean] | Includes a Maven project artifact in the class
loader which obtains the liquibase.properties file and
changelog files. Default value is:
true. |
liquibase.includeTestOutputDirectory [boolean] | Includes the Maven test output directory in the
class loader which obtains the liquibase.properties file and
changelog files. Default value is:
true.
|
liquibase.liquibaseProLicenseKey | Specifies your Liquibase Pro license key. |
liquibase.outputChangeLogFile | Specifies the target changelog file to output to. If this is null then the output will be to the screen. |
liquibase.outputDefaultCatalog [boolean] | Specifies whether to ignore the catalog or database name. Default value is: false. |
liquibase.outputDefaultSchema [boolean] | Specifies whether to ignore the schema name. Default value is: false. |
liquibase.outputFileEncoding | Indicates that you want to set the
character encoding of the output file during the updateSQL phase. |
liquibase.password | Specifies the database password for the database connection. |
liquibase.promptOnNonLocalDatabase [boolean] | Controls whether users are prompted before executing changesets to a non-local database. Default value is: true. |
liquibase.propertyFile | Specifies the liquibase.properties file you want to use to configure
Liquibase. |
liquibase.propertyFileWillOverride [boolean] | Indicates that you want the
liquibase.properties file to override any settings provided in the Maven plugin
configuration. By default, if a property is explicitly specified, it is not overridden if it also
appears in the properties file. Default value is: false. |
liquibase.propertyProviderClass | Specifies the property provider which must be a
java.util.Properties implementation. |
liquibase.server | Specifies the server ID in the Maven
settings.xml to use when authenticating. |
liquibase.skip [boolean] | Specifies whether to skip running Liquibase. The use of this attribute is not recommended but can be used when needed. Default value is: false. |
systemProperties | Specifies a list of system properties you want to pass to the database. |
liquibase.url | Specifies the database URL you want to use to execute Liquibase. |
liquibase.username | Specifies the database username for the database connection. |
liquibase.verbose [boolean] | Controls the amount of output detail when you call the plugin. Default value is: false. |