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.14
  • 2.12
  • 2.8
  • 2.6

Prerequisites

Install drivers

To use Liquibase and YugabyteDB, you need the JDBC driver JAR file (Maven download).

The latest version of Liquibase has a pre-installed driver for this database in the liquibase/internal/lib directory. Read more: Adding and Updating Liquibase Drivers.

If you use Maven, you must include the driver JAR as a dependency in your pom.xml file. Read more: Configuring Liquibase Attributes in your Maven POM File.

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.4.0</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. Liquibase does not parse the URL. You can either specify the full database connection string or specify the URL using your database's standard JDBC format:

    YugabyteDB on-premises

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

    When using 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

    YugabyteDB Managed (Cloud Cluster)

    url: jdbc:postgresql://us-west-2.936fe882-995b-4910-b020-cb00d2c281fb.aws.ybdb.io:5433/yugabyte?ssl=true&sslmode=verify-full&sslrootcert=<ROOT_CERT_PATH>
  3. To use a YugabyteDB Managed instance with Liquibase, download the root.crt file and specify sslmode as verify-full. Specify the path to the root.crt file in the url attribute. If not specified, the default location is ~/.postgresql.

    Tip: To apply a Liquibase Pro key to your project, add the following property to the Liquibase properties file: licenseKey: <paste code here>

  1. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.
  2. Navigate to your project folder in the CLI and run the Liquibase status command to see whether the connection is successful:
  3. liquibase status --username=test --password=test --changelog-file=<changelog.xml>

    Note: You can pass arguments in the CLI or keep them in the Liquibase properties file.

  4. Inspect the SQL with the update-sql command. Then make changes to your database with the update command.
  5. liquibase update-sql --changelog-file=<changelog.xml>
    liquibase update --changelog-file=<changelog.xml>
  6. From a database UI tool, ensure that your database contains the test_table you added along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table.