Using Liquibase with Snowflake

Snowflake enables data storage, processing, and analytic solutions and runs on the cloud infrastructure. Snowflake is a software-as-a-service (SaaS) offering:

  • There is no hardware (virtual or physical) to select, install, configure, or manage.
  • There is virtually no software to install, configure, or manage.
  • Ongoing maintenance, management, upgrades, and tuning are handled by Snowflake.

For more information, see the Snowflake documentation page.

Supported Versions

  • 5.24.0

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 Snowflake, you need to have two jar files – the JDBC and the Liquibase Snowflake extension:

  1. Ensure you have downloaded the Snowflake JDBC driver jar file to connect to the Snowflake database. To download the Snowflake driver jar file, go to the Maven Central Repository and select the version you need.
  2. Place the snowflake-jdbc-<version>.jar file in the liquibase/lib directory.
  3. Open the Liquibase properties file and specify the following driver value:
  4. driver: net.snowflake.client.jdbc.SnowflakeDriver
  5. Go to the liquibase-snowflake repository and download the latest released Liquibase extension liquibase-snowflake-<version>.jar file.
  6. Place the liquibase-snowflake-<version>.jar file in the liquibase/lib directory.

Note: If you place the snowflake-jdbc-<version>.jar and liquibase-snowflake-<version>.jar files in a different directory, specify the path in the Liquibase properties file, as follows: classpath:../path_to_drivers/snowflake-jdbc-<version>.jar; liquibase-snowflake-<version>.jar. For more information, see Specifying Properties in a Connection Profile.

  1. Install the JCE Unlimited Strength Jurisdiction Policy Files for Oracle Java if you use Oracle Java and need to encrypt stage files using 256-bit keys. After you download the zip file, which contains a README.txt file and two .jar files, put the two .jar files in the jre/lib/security subdirectory of your Java installation.

Note: The JDBC driver uses the AES specification to encrypt files uploaded to Snowflake stages. The JDBC driver automatically encrypts staged files using 128-bit keys. However, to use 256-bit keys instead of the default 128-bit keys for encryption of staged files, follow the Java Requirements for JDBC Driver documentation.

If you use Maven, you also need to download the Snowflake driver jar file 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>net.snowflake</groupId>
    <artifactId>snowflake-jdbc</artifactId>
    <version>4.0.0</version>
</dependency>

Additionally, you need to specify the Liquibase Snowflake extension in your pom.xml file as explained in Configuring Liquibase Attributes in your Maven POM File. Make sure that the Liquibase plugin and the extension have the same version.

<dependency>
    <groupId>org.liquibase.ext</groupId>
    <artifactId>liquibase-snowflake</artifactId>
    <version>4.4.0</version>
</dependency>

Testing Your Connection

For Liquibase and Snowflake to work, you need to:

  1. Ensure your Snowflake database is configured. To validate that Snowflake is available, you can use the SnowSQL CLI tool and run connect. You can also log into the Snowflake console in your browser to validate that the instance is running. The browser link is different for each Snowflake instance, but the format is the following: https://<cloudHostName>.snowflakecomputing.com. You will receive an email with the link when the database is ready for use.
  2. Specify the database URL in the Liquibase properties file, as follows:
  3. url: jdbc:snowflake://<account_ID>.snowflakecomputing.com/?<connection_params>

    Note: The account ID is the host name for your Snowflake instance. Snowflake sends an email with the URL to the host. The JDBC driver only needs the hostname, not the full URL: tn12345.us-east-1.snowflakecomputing.com.

    Example: Depending on the cloud provider you select during the database creation, your domain name will be different. The example is for an AWS cloud instance: jdbc:snowflake://tn12345.us-east-1.snowflakecomputing.com/?db=lbcat&schema=public.

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

  1. 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.

Related Links