How to avoid ValidationFailedException after Liquibase upgrade for Spring-based modules


This article describes how to avoid checksum validation issues after upgrading to the 4.3.5 version of Liquibase



Purpose

After updating to the Liquibase version 4.3.5, that will be done automatically if we update the folio-spring-base library version from 1.x.x to 2.x.x,  we can get ValidationFailedException during enabling the module for the tenant.

Options

  1. Maven command
  2. Application property
  3. RunOnChange attribute with precondition

Step-by-step guide

Maven command

We can clear and recalculate the Liquibase checksum using mvn liquibase:clearCheckSums command. The disadvantage of this option is that we have to do some manual work each time we are facing this issue.


Application property

The other option is to add a new property to our application properties: spring.liquibase.clear-checksums = true, which is applicable for all Spring-based modules. The disadvantage of this option is that we are disabling the benefits of checkSums.


RunOnChange attribute with precondition

This is the most convenient way to solve this problem. Each time we are writing the script to create some table, we need to add the runOnChange parameter to the changeSet and use precondition to not run this script if the table already exists. 

The example of creating the table with this params:


Script example of reating the table
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                   http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
  <changeSet id="01_create_test_table" author="testUser@folio.com" runOnChange="true">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="test_table"/>
      </not>
    </preConditions>
    <createTable tableName="test_table">
      <column name="id" type="SERIAL">
        <constraints nullable="false" primaryKey="true"/>
      </column>
      <column name="test_value" type="jsonb">
        <constraints nullable="false"/>
      </column>
    </createTable>
  </changeSet>
</databaseChangeLog>


runOnChange liquibase property - https://docs.liquibase.com/concepts/changelogs/attributes/runonchange.html
liquibase precondition - https://docs.liquibase.com/concepts/changelogs/preconditions.html