Evolving your database using Spring-boot and Liquibase

Overview

Harit Himanshu
7 min readMay 18, 2017

When developing web applications one of the common questions to consider is how to create database schema in production and how to evolve them going forward.

It is fairly known to use database migration tools which specialize in this area. These tools help you create the schema, run them during deployment and also help you write automated tests so that you are confident that your changes will work in production.

In the world of Java some of the known choices are Flyway and Liquibase. In this post, we will look into Liquibase as a way to perform database migrations.

Benefits

  • Write your schema and data agnostic of database. This is something that Flyway does not provide at this time. The benefit of this approach is that you specify your changes once and test them on different databases. For example, write tests again H2 and run the migration on MySQL without changing the code.
  • You could specify your changes in XML, YAML , JSON and SQL formats, pick your flavor. We are going to pick XML for its structured nature and a way to provide typed Values when inserting data (as we will see later).
  • You could pick and choose the changes to be applied in different environments(dev, staging, QA) if you have such a requirement. An example could be seed some static data in staging to test your application and not do that in production environment. (I will write a…

--

--

Harit Himanshu

Co-Founder https://bonsaiilabs.com/, Co-Creator https://moneybonsai.com. Interested in Personal Finance, FinTech, Programming, Technology, Teaching, Education