Liquibase checksum validation error without any changes

爱⌒轻易说出口 提交于 2019-11-28 19:07:46
Roy Truelove

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.

Mark O'Connor

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 chagelogs to database table.

Go to DATABASECHANGELOG table and remove manually your chagelogs.

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!

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!