Database Schema Migration Tools: Flyway & Liquibase + CockroachDB

Database Schema Migration Tools: Flyway & 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 online schema changes and online primary key changes into CockroachDB. 

The Benefits of Schema Migration Tools: Flyway & 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, 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.

x
Developer Resources