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: The supported versions are the versions that were tested with Liquibase Test Harness.

Prerequisites

Before using Liquibase with your database, ensure you have:

Driver Information

To use Liquibase and YugabyteDB, you need to have the JDBC jar file:

  1. Ensure you have downloaded the PostgreSQL JDBC jar driver file to connect to YugabyteDB.
  2. Place your postgresql-version.jar file in the liquibase/lib directory.

Note: If you placed the postgresql-version.jar file in a different directory, specify the path in the Liquibase properties file, as follows: classpath:../path_to_drivers/postgresql-version.jar. For more information, see Specifying Properties in a Connection Profile.

If you use Maven, you can alternatively download the PostgreSQL JDBC driver and put the 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:

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

Testing 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, as follows:

    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. Run your first update with the update command, which makes changes to your database. You can also run the update-sql command to inspect the SQL before running 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.