62

We're using Liquibase 3.2 with Java 6. Is there a way I can force Liquibase to recalculate checksums without re-running the same statements from our Liquibase files? In our database, I run this ...

update DATABASECHANGELOG set md5sum = null where 1;

However, when I run my Liquibase change scripts, certain executions still fail with the following errors ...

invoking liquibase change script with file /tmp/deploywork/db.changelog-master.xml
running /usr/java/liquibase/liquibase  --logLevel=info --driver=com.mysql.jdbc.Driver --classpath=/usr/java/jboss/modules/com/mysql/main/mysql-connector-java-5.1.22-bin.jar --changeLogFile=/tmp/deploywork/db.changelog-master.xml --url="jdbc:mysql://myservername:3306/my_db" --username=username --password=password update 
INFO 5/13/15 2:15 PM: liquibase: Successfully acquired change log lock
INFO 5/13/15 2:15 PM: liquibase: Reading from my_db.DATABASECHANGELOG
INFO 5/13/15 2:15 PM: liquibase: Successfully released change log lock
Unexpected error running Liquibase: Validation Failed:
     3 change sets check sum
          db.changelog-1.0.xml::1357593229391-25::rob (generated) is now: 7:5cfe9ecd779a71b6287ef2360a6979bf
          db.changelog-7.0.xml::create-address-email-index::davea is now: 7:da0132e30ebd6a1bc52d9a39bb8c56d7
          db.changelog-7.0.xml::add-myproject-event-object-id-col::davea is now: 7:2eab5d784647ce33ef3488aa8c383443


SEVERE 5/13/15 2:15 PM: liquibase: Validation Failed:
     3 change sets check sum
          db.changelog-1.0.xml::1357593229391-25::rob (generated) is now: 7:5cfe9ecd779a71b6287ef2360a6979bf
          db.changelog-7.0.xml::create-address-email-index::davea is now: 7:da0132e30ebd6a1bc52d9a39bb8c56d7
          db.changelog-7.0.xml::add-myproject-event-object-id-col::davea is now: 7:2eab5d784647ce33ef3488aa8c383443

liquibase.exception.ValidationFailedException: Validation Failed:
     3 change sets check sum
          db.changelog-1.0.xml::1357593229391-25::rob (generated) is now: 7:5cfe9ecd779a71b6287ef2360a6979bf
          db.changelog-7.0.xml::create-address-email-index::davea is now: 7:da0132e30ebd6a1bc52d9a39bb8c56d7
          db.changelog-7.0.xml::add-myproject-event-object-id-col::davea is now: 7:2eab5d784647ce33ef3488aa8c383443

    at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:181)
    at liquibase.Liquibase.update(Liquibase.java:191)
    at liquibase.Liquibase.update(Liquibase.java:174)
    at liquibase.integration.commandline.Main.doMigration(Main.java:997)
    at liquibase.integration.commandline.Main.run(Main.java:170)
    at liquibase.integration.commandline.Main.main(Main.java:89)

Here is one of the change sets that the script is complaining about …

    <changeSet author="davea" id="add-myproject-event-object-id-col">
        <addColumn tableName="sb_myproject_event">
            <column name="OBJECT_ID" type="VARCHAR(32)"/>
        </addColumn>
        <createIndex indexName="SB_myproject_EVENT_IDX"
            tableName="sb_myproject_event"
            unique="false">
            <column name="OBJECT_ID" type="varchar(32)" />
        </createIndex>
        <sql>update sb_myproject_event set object_id=LEFT(SUBSTRING_INDEX(event_data, '&quot;id&quot;:&quot;', -2), 24) where object_id is null and event_data is not null;</sql>
        <!--  Delete older events that no longer need to be processed -->
        <sql>delete from sb_myproject_event where id not in (select q.* from (select e.id FROM sb_myproject_event e, (select object_id, max(date_processed) d from sb_myproject_event group by object_id) o where e.object_id = o.object_id and e.date_processed = o.d) q);</sql>
    </changeSet>

As I said, I only want to recalculate checksums (have to do this because we're changing Liquibase versions).

Dave A
  • 2,780
  • 9
  • 41
  • 60

3 Answers3

85

Rather than clearing the checksums yourself using SQL, it will probably be better to let Liquibase do that by using the clearCheckSums command:

https://docs.liquibase.com/commands/community/clearchecksums.html

Removes current checksums from database. On next run checksums will be recomputed.

Kariem
  • 4,398
  • 3
  • 44
  • 73
SteveDonie
  • 8,700
  • 3
  • 43
  • 43
  • 2
    Hi, I added "--clearCheckSums" into the command listed above, but got the error, "SEVERE 5/14/15 3:09 PM: liquibase: Could not parse '--clearCheckSums'" – Dave A May 14 '15 at 15:10
  • 9
    `clearCheckSums` is a command (similar to update) and not an option - it doesn't need the `--` beforehand. – SteveDonie May 14 '15 at 20:48
  • 13
    update databasechangelog set md5sum=null where id like '%62%'; – Николай Мишин May 19 '16 at 09:31
  • 6
    if using gradle plugin, it can be started as: `gradlew clearChecksums` – xorcus Oct 31 '17 at 09:31
  • 2
    if using maven, there is goal clearCheckSums for this clearCheckSums – MathGuy Oct 17 '19 at 12:09
  • 1
    Per the Liquibase documentation "clearCheckSums Removes current checksums from database. On next update changesets that have already been deployed will have their checksums recomputed, and changesets that have not been deployed will be deployed." It does clear the MD5SUM column, but for me, the next update tries to re-run all of the changesets. Quite puzzled. – LinuxLars Apr 29 '20 at 18:47
  • 1
    For liquibase 4.4.0 command has been updated to `clear-checksums` – Nitin Jun 25 '21 at 18:37
2

Use the command below if you are using maven:

mvn liquibase:clearCheckSums
Mohamed Taher Alrefaie
  • 15,698
  • 9
  • 48
  • 66
1

For those interested in what liquisebase:clearCheckSums does is it basically runs this sql

UPDATE databasechangelog SET MD5SUM = NULL

Alternatively, you can truncate the 'databasechangelog' table; the new changelog entries will be inserted the next time liquibase is run.

If you are using jHipster they fixed this behavior in v7.x so that liquibase knows to re-compute check sums. (This is if you are getting the error related to failed check sum validations and you are sure the changelog entries you have are correct).

cluis92
  • 664
  • 12
  • 35