Generate your changelog from an existing database
Last updated: July 14, 2025
If you already have a working database and want to start managing it with Liquibase, the first step is to generate a changelog that captures the current state of your schema. This allows you to bring Liquibase into your existing project without disrupting your database or rebuilding anything from scratch.
Before you begin
Make sure you've installed Liquibase and can run
liquibase
from your command line.Connect your database to Liquibase. You'll need to follow the integration guide for your specific database.
Procedure
Generate your changelog
You can use the following example code. Be sure to:
Navigate to your Liquibase project folder in the CLI.
Set your_changelog_file_name to a name for the changelog file that will be generated, such as
dbchangelog
.Set your_file_extension to the format you'd like to use, such as
dbchangelog.xml
. Liquibase supports.sql
,.yaml
,.json
, and.xml
formats.
liquibase generate-changelog --changelog-file=your_changelog_file_name.your_extension
Note: After you create a Liquibase project using liquibase init project
, Liquibase generates a standard project structure, including a file named example-changelog.sql
. This file is only a sample, once you've generated your changelogs, you can delete it to avoid confusion.
Sync the changelog with your database
Once you have your changelog file, populate the DATABASECHANGELOG tracking table with the changesets from this changelog.
Liquibase keeps track of your already deployed changes with the help of its DATABASECHANGELOG tracking table.
To create this table for the first time, use the changelog-sync
command. The changelog-sync
command will populate the DATABASECHANGELOG table with the changesets metadata as if you have been using Liquibase all along.
liquibase changelog-sync --changelog-file=dbchangelog.xml
This command updates the tracking table so Liquibase knows your database is up to date with the changelog. It won’t make any schema changes.