Using Liquibase with HSQL

The purpose of this document is to guide you through the process of creating a new Liquibase project with HSQL. In this tutorial, you will learn how to install the required database drivers and configure the liquibase.properties file to establish a database connection to HSQL.

Prerequisites

  • Ensure that you have installed the latest version of Liquibase. If not, go to https://www.liquibase.org/download to install it.
  • Ensure that the Liquibase executable location is in the PATH environment variable.
  • Copy the JDBC driver for HSQL into the Liquibase/lib directory so that it will automatically be located when executing Liquibase commands. You can place it in any other known directory so you can locate it easily. The driver is automatically installed as a part of HSQL, however, you can also install it by going to https://sourceforge.net/projects/hsqldb/files/.

Tutorial

To create a Liquibase project with HSQL, perform the following steps:

  1. Create a new project folder and name it LiquibaseHSQL.
  2. In your LiquibaseHSQL folder, create a new text file and name it liquibase.properties.

Note: For more information about the liquibase.properties file, see Creating and configuring a liquibase.properties file.

  1. Edit the liquibase.properties file to add the following properties:
changeLogFile: dbchangelog.xml
url: jdbc:hsqldb:hsql://192.168.1.15:9001/MYDATABASE
username: user
password: password
driver: org.hsqldb.jdbcDriver
classpath: ../../Liquibase_Drivers/hsqldb.jar

Note: Specifying your password, take into account that Liquibase supports only the following special characters: ~ # $ % * ( ) - _ + [ ] { } . ?. Unsupported special characters are as follows: @ & / : < > " ' ` | ^ ! = , \ <spaces>.

Use the following format for the url property:

jdbc:hsqldb:hsql://<host>:<port>/<database>

Note: As an HSQL database can be run in two modes—standalone and server, the url property formats differ. The standalone mode runs the database engine as part of your application program, and the software runs in the same local thread. If you use the standalone mode of HSQL, follow this format of the url property:

jdbc:hsqldb:file:<database>
  • If you placed your jdbc driver file in the Liquibase/lib install directory, there is no need to specify the classpath property in the liquibase.properties file. Otherwise, put the path to your driver as it is shown in the preceding example.
  • If you already have a Liquibase Pro key and want to apply it to your project, add the following property to your liquibase.properties file:
liquibaseProLicenseKey: <paste license key>
  1. Create a changelog file. The changelog files contain a sequence of changesets, each of which makes small changes to the structure of your database. For more information, see changelog. Liquibase provides a changelog template located at $LIQUIBASE_HOME/examples/xml/blank.changelog.xml. Copy the blank.changelog.xml file to your LiquibaseHSQL folder and rename it to dbchangelog.xml. Each version of Liquibase will have an updated XML schema, so use the one that matches the version of Liquibase you have installed. The contents of the changelog will be similar to 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"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
 </databaseChangeLog>

Note: The preceding changelog is XML format. The corresponding SQL changelog statement looks like the following:

--liquibase formatted sql
  1. Verify the project configuration. Run the status command to verify that the configuration is complete. Open a command prompt and navigate to the project folder LiquibaseHSQL. Run the command as follows:
liquibase status
  1. Verify that the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables were created. From a database UI Tool, check your new Liquibase tables.

DATABASECHANGELOG tracking table. This table keeps a record of all the changesets that were deployed. When you add changesets to your changelog and run the update command, the changesets in the changelog will be compared with the DATABASECHANGELOG tracking table, and only the new changesets that were not found in the DATABASECHANGELOG will be deployed.

DATABASECHANGELOGLOCK tracking table. This table is used internally by Liquibase to manage access to the changelog table during deployment.

Congratulations!

You have successfully configured your project and can begin creating changesets to migrate changes to your database. For more information on how to create changesets, see changeset.

See also