Member-only story
Evolving your database using Spring-boot and Liquibase
Overview
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 onMySQL
without changing the code. - You could specify your changes in
XML
,YAML
,JSON
andSQL
formats, pick your flavor. We are going to pickXML
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 instaging
to test your application and not do that inproduction
environment. (I will write a…