Safely Evolving Database with Liquibase, Spring Data, and Spring Boot


This blog post explains the process to safely evolve Database with Liquibase, Spring Boot, and Spring Data JPA. Liquibase Maven plugin gives the ability to perform liquibase operations through maven commands and Liquibase Hibernate plugin helps to generate liquibase changesets based on JPA entities. Code uploaded to Github for reference

Technologies Used

  1. Spring Boot 2.x
  2. Spring Data JPA 2.x
  3. Java 11
  4. Liquibase 4.0.0
  5. Liquibase Hibernate plugin 3.10.1
  6. Liquibase Maven plugin 4.0.0


  1. Clone the Github repository into local machine
  2. Add required dependencies for Spring Boot, Spring Data, Liquibase, etc. based on below mentioned pom.xml file
package com.liquibasedemo.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.persistence.*;

@Table(name = "country")
public class Country
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;

@Column(name = "name")
private String name;

@Column(name = "code")
private String code;

@Column(name = "iso_code")
private String isoCode;

@JoinColumn(name = "region_id")
private Region region;

public Country()


package com.liquibasedemo.repo;

import com.liquibasedemo.model.Country;

public interface CountryRepository extends JpaRepository<Country, Long>


package com.liquibasedemo.web;

import com.liquibasedemo.model.Country;
import com.liquibasedemo.repo.CountryRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

public class CountryController
private final CountryRepository countryRepository;

public CountryController(CountryRepository countryRepository)
this.countryRepository = countryRepository;

@GetMapping(path = "/list")
public List<Country> findAllCountries()
return countryRepository.findAll();

@GetMapping(path = "/create")
public Country createCountry()
Country country=new Country();
country.setName("United States Dollar");

return countryRepository.saveAndFlush(country);
ddl-auto: update
Directory Structure
Local Database Changes
$ mvn clean package -DskipTests
Liquibase Diff Command
Liquibase Update Command



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavan Jadda

Pavan Jadda

Full Stack Developer(Java, Angular and React)