Database Change Management Tool: Liquibase with Snowflake Overview

Rajiv Gupta
7 min readAug 20, 2021

In this blog we are going to discuss how we can utilize Liquibase, a Database Change Management Tool, to deploy database objects & dml scripts in Snowflake. This can be achieved in many ways and using many tools in the market. You can also develop your own custom tool to achieve a certain level of management. But I am a fan of liquibase as it gives me lots of flexibility and end numbers of features. It is supporting lots of databases, either natively or community-developed jars. Let's start discussing all its features & benefits one by one.

What is Liquibase?

Liquibase is an open-source database migration tool that provides organizations with an effortless way to track, version, and deploy database schema changes. It is different from other database migration tools because the software understands the changes you are making based on how you specify those changes.

  1. Liquibase uses commands and Change Types (changes to database schemas) that allow you to specify what you need Liquibase to do and how you want it to be done.
  2. Liquibase uses changelogs and tracking tables to determine what is deployed to the database after the commands have been run.

What are the key features of Liquibase?

  1. Compatibility with a broad range of databases, such as

2. For a complete list of native and community-supported databases, see the documentation.
3. A flexible extension framework that allows for seamless additions of newly released platforms and integrations.
5. Full control of when, where, and how database changes are deployed.

Liquibase Supports Multi-Language for Schema Change?

Yes, liquibase support multiple languages for schema change file. This gives the developer a choice in which he/she want to write changelog. It also helps reuse the existing skill set of the team as it has all famous language support.

What are the advanced features supported in Liquibase?

Liquibase also has advanced features such as :

Context
Labels
Preconditions
Include <Tag>
Include All

That precisely controls when and where a change is deployed. You can learn more about these in the Liquibase Advanced Concepts documentation.

How Liquibase support CI/CD for databases ?

Liquibase is flexible enough to work with just about every tool in whatever variation that tool is provided. Some tools control Liquibase through a plugin, while most leverage the Liquibase CLI either in a native deployment, or a Docker container.
Implementing end-to-end CI/CD requires all code (including database code) to be checked in to a version control system and be deployed as part of the software release process. Liquibase can help you achieve this. Each database schema change you make with Liquibase is called a changeset. All changesets are tracked by Liquibase using changelogs. Liquibase allows you to create a trigger that updates the database automatically by pointing to the changelog file. From here, it makes it easy to integrate the process into your overall CI/CD process:

Push your changeset files to your feature repository
Create a pull request against the Dev branch
After peer review and approvals, merge the feature branch with the Dev branch
The CI/CD implementation configured on the Dev server triggers Liquibase for database updates
Liquibase automatically executes any new changelog files (and is awesome enough to remember which scripts have already run)

ChangeLog Sample Code Snippet:

Do we need to Install Liquibase?

Yes, liquibase comes with an installer. You can download & install liquibase from here. Liquibase is a java based tool.

Is there any prerequisite for Liquibase installation?

Yes, there are few System requirements that needs to be met to install liquibase. Also, the below needs to be honored before you can use Liquibase with Snowflake.

  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 driver value in it:
driver: net.snowflake.client.jdbc.SnowflakeDriver
  1. Go to the liquibase-snowflake repository and download the latest released Liquibase extension liquibase-snowflake-<version>.jar file.
  2. Place the liquibase-snowflake-<version>.jar file in the liquibase/lib directory.

How Liquibase Works?

There are two main mechanisms, or concepts, that are the foundation of Liquibase. These two concepts are:

  1. Schema Changes consist of changelogs, changesets, and Change Types.
  2. Tracking tables that record database changes.

It is important to understand Liquibase terminology. Some of these you may already know, and some you may be seeing for the first time. The list below includes the most common terms when using Liquibase in your day-to-day operations.

  • Project — a collaborative enterprise that is carefully planned and designed to achieve a particular aim.
  • Database — an organized collection of data, generally stored and accessed electronically from a computer system.
  • Command Line Interface (CLI) — a text-based interface that allows you to view and modify your files. The CLI allows you to enter a variety of Liquibase commands in a text-based format.
  • Changelog — acts as a ledger of changes and contains a list of changesets (units of change) that Liquibase can execute on a database.
  • Changeset — a unit of change that occurs to a database and is indicated by a changeset tag <changeset> in XML or — changeset author:id in SQL. The changeset tag contains that unit of change (which is specified by a change type — or the type of change you want to make) and is identified by the id tag, author tag, and changelog file classpath name.

How liquibase support default properties?

Liquibase comes with a property file, which is a simple text file named as liquibase.properties. This file can be used to store all default parameter which is not going to change frequently. It is not recommended, but you can also store passwords for your target database.

You can typically use this file to specify your database connection information. Using the liquibase.properties file saves you time and potential typing errors by removing the need to enter these properties as command line arguments.

More details can be found in the documentation here.

Sample liquibase.properties file below:

What are common liquibase commands?

Below are common commands used when working with Liquibase. They include:

  • update — applies to all unrun changes.
  • rollback — reverts (rolls back) changes you have made to your database.
  • snapshot — used when you want to quickly compare changes in your database or keep a record of your current database state.
  • dbDoc — generates database change documentation.
  • diff — allows you to compare two databases of the same type or different types to one another.
  • diffChangeLog — used when you want to create a deployable changelog to synchronize multiple databases.
  • generateChangeLog — creates a changelog file that has a sequence of changesets that describes how to re-create the current state of the database.
  • rollbackOneChangeSet — reverts (rolls back) one non-sequential changeset made during a previous change to your database.
  • rollbackOneUpdate — reverts (rolls back) all changesets related to a specific deploymentId made during a previous change to your database.
  • rollbackOneUpdateSql — a helper command that allows you to inspect the SQL Liquibase will run to revert all changesets associated with the deploymentID specified in the rollbackOneUpdate command.
  • rollbackOneChangeSetSql — a helper command that allows you to inspect the SQL Liquibase will run to revert the changeset specified in the rollbackOneChangeSet.
  • history — a helper command that lists out all your deploymentIds and all changesets associated with each deploymentId.

Liquibase Key Observation:

  1. Liquibase is java based, so connect with any application via JDBC driver.
  2. Multiple databases are supported natively, while few are also supported by community developer extension.
  3. Liquibase is available in the community version(free) as well as fully supported PRO, Business & Enterprise version.
  4. It is supported by almost every CI/CD tool. Some tools control Liquibase through a plugin, while most leverage the Liquibase CLI either in a native deployment, or a Docker container.
  5. Liquibase Supports Multi-Language for Schema Change like SQL, XML, JSON, YAML.
  6. Liquibase Supports:

Ability to merge changes from multiple developers.
Code branches.
Multiple databases.
Cluster-safe database upgrades.
Generation of starting changelogs from existing databases.
Generation of database change documentation.
Automated updates or generation of SQL.
Generate SQL’s before applying to database for verification.

Hope this blog helps you to get insight on Liquibase. Feel free to ask a question in the comment section if you have any doubts regarding this. Give a clap if you like the blog. Stay connected to see many more such cool stuff. Thanks for your support.

You Can Find me:

Follow me on Medium: https://rajivgupta780184.medium.com/

Follow me on Twitter: https://twitter.com/RAJIVGUPTA780

Connect with me in LinkedIn: https://www.linkedin.com/in/rajiv-gupta-618b0228/

Subscribe to my YouTube Channel: https://www.youtube.com/channel/UC8Fwkdf2d6-hnNvcrzovktg

#Keep learning #Keep Sharing #EverydayLearning.

References:-

Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

--

--

Rajiv Gupta

Sr. Architect at Cognizant, Snowflake Data Super Hero, Snowflake SME