Using Liquibase with Vertica

The purpose of this document is to guide you through the process of creating a new Liquibase project with Vertica. In this tutorial, you will generate an example project and follow the instructions to apply and learn concepts associated with creating new Liquibase projects with Vertica.

Prerequisites

Before using Liquibase with your database, ensure you have:

Note: If you use Maven, you also need to download the .jar file from the Maven repository. Additionally, specify the Liquibase extension in your pom.xml file by referring to Configuring Liquibase Attributes in your Maven POM File and make sure that the Liquibase plugin and the extension have the same version.

Tutorial

To create a Liquibase project with Vertica on your machine, begin with the following steps:

  1. In your project folder, create a new text file and name it dbchangelog.sql. Add the following code snippet:
--liquibase formatted sql
  1. Add the following properties to the Liquibase properties file:
  2. changelog-file: dbchangelog.sql
    url: jdbc:vertica://localhost:5433/docker
    username: dbadmin
    driver: com.vertica.jdbc.Driver
    password: password

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

  1. Add a changeset to the changelogchangeset are uniquely identified by author and id attributes. Liquibase attempts to execute each changeset in a transaction that is committed at the end. In the dbchangelog.sql file line 3 add a new “department” create table change set as follows:
  2. 
    --liquibase formatted sql
    
    --changeset bob:1
    CREATE TABLE "DEPARTMENT" ("ID" INTEGER, "NAME" CHAR(20), "ACTIVE" BOOLEAN);
  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

For example, from the SQL Developer Tool User Interface, check your database changes under “public schema”. You should see a new “department” table added to the database:

SELECT * FROM "public"."DEPARTMENT";
ID NAME ACTIVE
NULL NULL NULL

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