Using Liquibase with YugabyteDB

YugabyteDB is an open-source, high-performance, distributed SQL database for global, internet-scale apps. It can be run on your local machine as well as a cloud cluster. For more information, see the YugabyteDB documentation page.

Supported versions

  • 2.6

Note: Supported versions tested with Liquibase Test Harness.

Prerequisites

Install drivers

To use Liquibase and YugabyteDB, you need to have the JDBC driver JAR file.

Liquibase comes with a pre-installed driver for this database in the liquibase/internal/lib directory. For more information, see Adding and Updating Liquibase Drivers.

If you use Maven, you also need to download the driver JAR file and configure your Maven pom.xml file to use the local copy of the driver. For more information, see Configuring Liquibase Attributes in your Maven POM File. For example:

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.3.4</version>
</dependency>

Test your connection

  1. Ensure your YugabyteDB is configured. You can check its status depending on your cluster setup. Run the yugabyted command:

    ./bin/yugabyted status
  2. Specify the database URL in the Liquibase properties file:

    url:jdbc:postgresql://localhost:5433/<database_name>

    When using the YugabyteDB on-premises and specifying the URL, enter your IP address or host name, the port, and the database name. An example of the format is:

    jdbc:postgresql://<IP OR HOSTNAME>:<PORT>/<DATABASE>

    The default username and password is yugabyte for both. Add them to the Liquibase properties file, as follows:

    url: jdbc:postgresql://localhost:5433/yugabyte
    username: yugabyte
    password: yugabyte
  3. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.
  1. Navigate to your project folder in the CLI and run the Liquibase status command to see whether the connection is successful. You can pass arguments in the CLI or keep them in the Liquibase properties file.
  2. liquibase --username=test --password=test --changelog-file=<changelog.xml> status
  3. Inspect the SQL with the update-sql command. Then make changes to your database with the update command.
  4. liquibase --changelog-file=<changelog.xml> update-sql
    liquibase --changelog-file=<changelog.xml> update

From a database UI tool, ensure that your database contains the table you added along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table.