Question

Maven fires liquibase validation fail even no changes was made in changeset.

My database is oracle.

Situation:

  1. In DB changelog table was record for changeset <changeSet id="1" author="me" dbms="oracle">;

  2. Then by mistake i added another changeset <changeSet id="1" author="me" dbms="hsqldb">

  3. Reruned liquibase scripts Maven fired checksum validation error.

  4. Then i changed hsqldb changeSet to <changeSet id="2" author="me" dbms="hsqldb">

  5. Maven still firing checksum validation error.

  6. Then i changed first changeSet checksum in DB manually to current checkSum and scripts runned successfully.

Everything looks nice ,but when i redeploy whole application and run liquibase scripts checksum of first changeSet is still like before 6 step.

Was it helpful?

Solution

If you're confident that your scripts correctly reflect what should be in the database, run the liquibase:clearCheckSums maven goal, which will clean it all up.

OTHER TIPS

Checksum validation errors are thrown by liquibase to indicate that the changes applied to the database no longer match the same content specified within the liquibase changeset files....

This is a safety measure designed to detect mis-behaving specification files and can easily happen during development. The best way to fix the problem is drop all objects and run liquibase against the development environment fresh as follows:

mvn liquibase:dropAll liquibase:update

Warning - this will drop all objects in the schema. You will lose all data in tables, and any object not managed by Liquibase. Documentation for drop-all goal

Sometimes you actually want to support changing changesets. In those circumstances liquibase supports a "runOnChange" attribute which selectively applies the changesets against the database instance.

In my case I forgot that Liquibase writes all changelogs to database table.

Go to DATABASECHANGELOG table and remove manually your changelogs.

Liquibase reads the databasechangelog table to validate the recent changes. So identify the databasechnagelog id which is causing the problem and delete, as shown below:

select * from myschema.DATABASECHANGELOG;

Delete from myschema.DATABASECHANGELOG where ID='prob_id';

Deleting a bad changelog in Liquibase

Everyone here is talking about how to fix this, but let me share a typical scenario where it may occur for you.

SHORT ANSWER : Change in line-separator due to one reason or another can cause checksum validation error and won't be visible in code changes.

Why did it occur for me? Please read below..

Suppose you have a tomcat server, and multiple people are involved in WAR deployment from time to time. Everyone uses INTELLIJ IDEA on LINUX but one of the team member switches to WINDOWS for some reason. Now, when the WINDOWS PERSON would create WAR, he may not notice that default line-separator selection in INTELLIJ IDEA for WINDOWS is CRLF but all previous builds built from LINUX machine which uses LF line-separator.

Change in line-separator affects all text files, which includes SQL files too. So you may have used following just like my team in your liquibase script

changeSet(author: "aditya", id: "1335831637231-1") {
    sqlFile( path: "liquibase/quartz_oracle_tables.sql", "stripComments": true)
}

and the checksum of file would not match the one already stored in database throwing checksum validation error.

As I struggle with this one I want to make it easier for people with this same issue:

  1. Important!, liquibase has a liquibase has a changlog.xml file
  2. On the maven pom.xml place the following properties.

<project ...>
  <plugins>
    <plugin>
      <groupId>org.liquibase</groupId>
      <artifactId>liquibase-maven-plugin</artifactId>
      <version>*****</version>
      <configuration>
        <changeLogFile>src/main/resources/mychangelogfile.xml</changeLogFile>
        <driver>oracle.jdbc.driver.OracleDriver</driver>
        <url>jdbc:oracle:thin:@//X.X.X.X:PORT/XE</url>
        <username>yourusername</username>
        <password>password</password>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>clearCheckSums</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</project>

**** version the one I used 3.2.0 in url replace with proper IPADDRESS and PORT.

Finally you run mvn liquibase:clearCheckSums

Hope it helps!

Configure liquibase's database link information in the maven plugin.

like this:

<plugin>
  <groupId>org.liquibase</groupId>
  <artifactId>liquibase-maven-plugin</artifactId>
  <version>${liquibase.version}</version>
  <configuration>
    <changeLogFile>${project.basedir}/src/main/resources/config/liquibase/master.xml</changeLogFile>
    <driver>com.mysql.cj.jdbc.Driver</driver>
    <url>jdbc:mysql://localhost:3306/hos_gateway</url>
    <username>root</username>
    <password>root</password>
    <referenceUrl>hibernate:spring:com.hos.physician.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
    <verbose>true</verbose>
    <logging>debug</logging>
    <contexts>!test</contexts>
  </configuration>
</plugin>

Changeset id should not repeat. Give a new changeset id and try, it should work.

<changeSet id=
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top