Denis Stephanov
Denis Stephanov

Reputation: 5231

Liquibase is trying to execute executed scripts

we need rename changelog files which are already executed by liquibase to use relative path of master file.

When we changed filesnames in master change log from this

<include file="src/main/resources/db/changelogs/changelog-1.26.xml"/>` 

to

<include relativeToChangelogFile="true" file="db/changelogs/changelog-1.26.xml"/>

From this change Liquibase always trying to execute same scripts which were executed in past.

Can you tell me how to solve this? We really need change this path to be able execute scripts from test scope.

Upvotes: 0

Views: 3041

Answers (3)

user158037
user158037

Reputation: 2603

Just in case anyone encounters similar problem: if liquibase tries to execute same script again, even in one run, try fiddling with ./ or trailing / in changelog xml/yaml. In my case it tried to run 1.sql, 2.sql, 3.sql and then ./1.sql - which failed for obvious reasons. Removing trailing "/" from path helped.

Upvotes: 0

Carlos Marmolejo
Carlos Marmolejo

Reputation: 146

When Liquibase tries to execute the script will compare the checksum to see if there's any change to be done, and you will have something like this (in the logs):

1 change sets check sum
          [filename]::[id]::[author]was: 7:eec7ef2a0dd6f5dc96c7a488f3943ff0 
          but is now: 7:6e98cd45fc25cf5fc182fb751b5349ff

So, you can update the record in the DATABASECHANGELOG table with something like this:

UPDATE DATABASECHANGELOG SET MD5SUM = '7:6e98cd45fc25cf5fc182fb751b5349ff' 
WHERE (ID = [id]) and (AUTHOR = [author]) and (FILENAME = [filename]);

This will prevent a new execution of the same script.

If someone knows how Liquibase calculates the checksum, that will be awesome, right now I'm only able the get the checksum after the execution (from the logs), I tried getting the checksum from the terminal, but it doesn't match with the one from Liquibase

Upvotes: 0

Tom Drake
Tom Drake

Reputation: 537

Without specifics, it's nearly impossible to give valid advice. However, Liquibase creates an entry in the change log table in your database for each 'change' that it executes. It computes a checksum for each of these comprised of values which are pertinent to each change. If you ever modify any of your changes, the computed checksum will no longer be the same, and won't match the one stored in your database, and Liquibase will then try and execute the 'updated' change. If you can get away NOT making changes to your prior liquibase changesets, I'd recommend that approach. However, if you must make changes, you may be able to use specify preconditions that would prevent the sort of errors you're describing.

Upvotes: 1

Related Questions