Database schema migration tools: Flyway and Liquibase + CockroachDB

Database schema migration tools: Flyway and Liquibase + CockroachDB

If you use a database, at some point you’ll need to modify your schema design. Maybe you need to store new kinds of information. Perhaps you’ll add a field to a table or even need to change a primary key. Regardless of the reason, application requirements tend to change over time - and you’ll need to migrate. We know how important schema modification is, which is why we’ve built zero-downtime online schema changes and online primary key changes into CockroachDB. 

The Benefits of Schema Migration Tools: Flyway and Liquibase

Over the last year, we’ve realized that many of our customers like using third-party schema migration tools to ease these transitions and to provide structure and control over the process. For this reason, CockroachDB has built official support for FlywayDB and Liquibase - the two most popular schema migration tools. 

Flyway and Liquibase both deliver version control for your database - which makes schema migrations more simple. Here is a short list of ways that schema migration tools increase developer efficiency:

  • They automatically order scripts for deployment 
  • They do branching and merging for teams 
  • They embed easily into products or build tools (think Jenkins
  • They make it easy to roll back changes 
  • They let you reproduce schema changes across multiple environments 
  • They provide automation so you can do schema changes automatically without having to remember all the commands

With Flyway developers write migration files in SQL or Java. With Liquibase (an open source project) developers can write changes in SQL, XML, YAML and JSON formats. 

Another benefit of using a tool like Flyway or Liquibase is that it can be used as a single source of truth of schema across multiple environments. This is helpful when you need to deploy the same set of changes to different databases, such as your development, staging, and production instances.

Database Schema Migration Tutorials

The process of migrating schema is, for some reason, excluded from most computer science program curriculums. As a result, a lot of young developers approach schema migrations with fear. The truth is that migrations can be confusing, but the tools are extremely helpful, and after you do one or two you’ll never worry about it again.

Here is a short video tutorial in which Rafi Shamim, an engineer on our App Dev team, demonstrates how you would use Flyway to perform a schema migration on a local CockroachDB instance:

(Sneaky pro tip from the tutorial: Don’t store passwords in plain text. Instead you should hash and salt them.)

Our Docs team has written a comprehensive tutorial on how to use Flyway with CockroachDB, as well as how to use Liquibase with CockroachDB. After you’ve digested either the video tutorial or the written tutorials head over to our community slack channel to ask followup questions relevant to your particular application architecture. CockroachDB engineers are in the slack channel and will respond with recommended solutions. 

Of note: People use the term “Schema Migration” and “Schema change” interchangeably. If you didn’t already know this, hopefully it clears up some confusion. And if you’re a Liquibase fan then you should check out this hands-on-keyboard we did with the founder, Nathan Voxland:\

Dan Kelly linkedin link

Dan has been producing technical blogs, videos, whitepapers, and webinars at Cockroach Labs for the last 4+ years. His mission is to identify the most pressing problems developers face and to create content to solve them. Outside of work Dan is usually chasing his three year old daughter or cooking something indulgent.

Keep Reading

How online schema changes are possible in CockroachDB

I periodically need to make changes to tables. Adding columns is very simple with the ALTER TABLE command… But my tables …

Read more
SQL compatibility in CockroachDB: Spatial data, Enums, materialized views

CockroachDB empowers developers to build fast, scalable applications, and one of the ways it does this is by providing …

Read more
How we built a CockroachDB dialect for Hibernate

This post was originally published in 2017, upon announcing that CockroachDB’s support for Hibernate …

Read more