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.
Before using Liquibase with your database, ensure you have:
- Installed Liquibase.
- Created a Liquibase project folder to store all Liquibase files.
- Created a new Liquibase properties file or are using the existing
liquibase.propertiesfile included in the installation package. For more information, see Specifying Properties in a Connection Profile.
- Downloaded the Vertica JDBC jar driver file.
- Downloaded the latest Liquibase extension jar file for Vertica.
- Placed the two jar files in the
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.
To create a Liquibase project with Vertica on your machine, begin with the following steps:
- In your project folder, create a new text file and name it
dbchangelog.sql. Add the following code snippet:
--liquibase formatted sql
- Add the following properties to the Liquibase properties file:
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>
- Add a changeset to the changelog – changeset are uniquely identified by
idattributes. Liquibase attempts to execute each changeset in a transaction that is committed at the end. In the
dbchangelog.sqlfile line 3 add a new “department” create table change set as follows:
--liquibase formatted sql --changeset bob:1 CREATE TABLE "DEPARTMENT" ("ID" INTEGER, "NAME" CHAR(20), "ACTIVE" BOOLEAN);
- 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.
- 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
liquibase --username=test --password=test --changelog-file=<changelog.xml> status
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";