Using Liquibase with H2

H2 is a standard SQL database that you can use to simulate anything required to be done in your own database.

Note: For more information, see the H2 page.

The web-based console allows you to see all objects in your database in the left navigation and run SQL statements on the right side. The console includes the Refresh button, which you can use to reload the left-side object view if you make changes to your database with Liquibase.

Supported Versions

  • 1.4.200

Note: The supported version is the version that was tested with Liquibase Test Harness.


Before using Liquibase and H2, ensure you have completed the following:

  • Installed Liquibase.
  • Created a Liquibase project folder to store all Liquibase files. Also, you can use the example directory included in the installation package for the H2 database.
  • Created a new file or are using the existing file. For more information, see Creating and configuring a file.

Driver Information

To use Liquibase and H2, you need to have the JDBC driver .jar file. Liquibase includes the H2 in-memory database and the h2-version.jar file in liquibase/lib in the installation package. For more information, see Adding and Updating Liquibase Drivers.

You can find the H2 database in the ../examples: start-h2.bat folder along with the sample SQL and XML changelogs and the file. You can find the h2-version.jar file in the liquibase/lib directory.

If you use Maven, put the H2 driver in a location that your Maven build can access. Configure the Maven pom.xml file to use the local copy of the driver jar file. For example:


Testing Your Connection

For Liquibase and H2 to work, you need to:

  1. Start the H2 database by navigating to the examples folder in the CLI and running start-h2.
  2. Note: To stop the example H2 database, you can use ctrl-c.

    The start-h2 script starts a local H2 database on port 9090 and opens the database console on the same port in the browser.

    Note: The example H2 database does not store data and will reset to its starting state when the start-h2 process ends.

    • A developer database corresponds to what you may use as a local database.
    • An integration database corresponds to another database in your pipeline.

    Note: You can view the integration database with the link provided from the developer database browser. You can also see which database you are connected to by looking at the URL at the top of the object view.

  1. Check the status of the database by entering create table test_table (id int) in the text area and select Run. You will see TEST_TABLE appear in the object view.
  2. Use a sample XML or SQL Working with Changelogs file, or create a new text file called changelog (.xml, .sql, .json, or .yaml).
  3. Add a Changelog Formats .
  4. Tip: If you already have a Liquibase Pro key and want to apply it to your project, add the following property to your file: liquibaseProLicenseKey: <paste license key>. For more information about the file, see Creating and configuring a file.

  1. Run the status command to see whether the connection is successful. Specify the name of the changelog you created in place of changelog.xml. Also, to run Liquibase commands, you need to specify your username and password in the file or on the command line. However, the username and password attributes are not required for connections and systems which use alternate means of authentication.
  2. liquibase --username=test --password=test --changeLogFile=changelog.xml status

    Note: Alternatively, you can add the changeLogFile attribute to your file.

  1. Run your first update with the Liquibase update command, which will make changes to your database:
  2. liquibase --changeLogFile=changelog.xml update

After your first update, your database will contain the table you added along with the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables:

  • DATABASECHANGELOG table. This table keeps a record of all the changesets that were deployed. When you deploy, the changesets in the changelog are compared with the DATABASECHANGELOG tracking table, and only the new changesets that were not found in the DATABASECHANGELOG will be deployed.
  • DATABASECHANGELOGLOCK table. This table is used internally by Liquibase to manage access to the DATABASECHANGELOG table during deployment and ensure only one instance of Liquibase is updating the database at a time, whether that is creating, updating, or deleting changes.

Supported Commands and Change Types

Change Type Supported Command Supported
addAutoIncrement Supported calculateCheckSum Supported
addCheckConstraint Not Supported changelogSync Supported
addColumn Supported changelogSyncSQL Supported
addDefaultValue Supported changelogSyncToTag Supported
addForeignKeyConstraint Supported changelogSyncToTagSQL Supported
addLookupTable Supported clearCheckSums Supported
addNotNullConstraint Supported dbDoc Supported
addPrimaryKey Supported deactivateChangeLog Supported
addUniqueConstraint Supported diff Supported
alterSequence Supported diff JSON Supported
createFunction Supported diffChangeLog Supported
createIndex Supported dropAll Supported
createPackage Supported futureRollbackCountSQL Supported
createPackageBody Supported future-rollback-from-tag-sql Supported
createProcedure Supported futureRollbackSQL Supported
createSequence Supported generateChangeLog Supported
createSynonym Not Supported help Supported
createTable Supported history Supported
createTrigger Supported listLocks Supported
createView Supported markNextChangeSetRan Supported
customChange Supported markNextChangeSetRanSQL Supported
delete Supported registerChangeLog Supported
disableCheckConstraint Not Supported releaseLocks Supported
disableTrigger Not Supported rollback Supported
dropAllForeignKeyConstraints Supported rollbackCount Supported
dropCheckConstraint Not Supported rollbackCountSQL Supported
dropColumn Supported rollbackOneChangeSet Supported
dropDefaultValue Supported rollbackOneChangeSetSQL Supported
dropForeignKeyConstraint Supported rollbackOneUpdate Supported
dropFunction Supported rollbackOneUpdateSQL Supported
dropIndex Supported rollbackSQL Supported
dropNotNullConstraint Supported rollbackToDate Supported
dropPackage Supported rollbackToDateSQL Supported
dropPackageBody Supported snapshot Supported
dropPrimaryKey Supported snapshotReference Supported
dropProcedure Supported status --verbose Supported
dropSequence Supported syncHub Supported
dropSynonym Not Supported tag command Supported
dropTable Supported tagExists Supported
dropTrigger Not Supported unexpectedChangeSets Supported
dropUniqueConstraint Supported update Supported
dropView Supported updateSQL Supported
empty Supported updateCount Supported
enableCheckConstraint Not Supported updateCountSQL Supported
enableTrigger Not Supported updateTestingRollback Supported
executeCommand Supported updateToTag Supported
insert Supported updateToTagSQL Supported
loadData Supported validate Supported
loadUpdateData Supported    
markUnused Not Supported    
mergeColumns Supported    
modifyDataType Supported    
output Supported    
renameColumn Supported    
renameSequence Not Supported    
renameTable Supported    
renameTrigger Not Supported    
renameView Not Supported    
setColumnRemarks Supported    
setTableRemarks Supported    
sql Supported    
sqlFile Supported    
stop Supported    
tagDatabase Supported    
update Supported    

Related Links