spring-bootliquibase

MD5 sums do not add up between migration with spring-boot and liquibase-cli


I am running my database migrations with liquibase (4.27.0) via the springboot starter

<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.2</version>

In order to reporduce the md5sum manually ran the cli (also 4.27.0) with the following command

    cd <path-to-my-project>/src/main/resources; \
    liquibase \
    --search-path=. \
    changelog-sync-sql \
    --changelog-file=db.changelog-master.xml \
    --url=jdbc:postgresql://localhost:5432/mydb \
    --default-schema-name=public \
    --password=test\
    --username=test

I moved src/main/resources/db/changelog/db.changelog-master.xml to src/main/resources/db.changelog-master.xml because liquibase had problems with the includeAll option when using the --search-path. My db.changelog-master.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">
    <preConditions>
        <dbms type="postgresql"/>
    </preConditions>
    <includeAll path="db/changelog/migration"/>
</databaseChangeLog>

It did not work out. The hashes that are being computed are different. Whats the problem?


Solution

  • I am going to answer my own question now:

    The solution: Don't use --search-path. use --classpath instead and set the changelog-file to the same path that you use in your application.properties in spring boot (exception for the classpath:).

    liquibase \
    --classpath=<path-to-my-project>/src/main/resources \
    changelog-sync-sql \
    --changelog-file=db/changelog/db.changelog-master.xml \
    --url=jdbc:postgresql://localhost:5432/fim3_dev \
    --default-schema-name=public \
    --password=dev \
    --username=dev
    

    This worked out fine and the hashes were computed equally. Why this works with respect to the other option, I don't know exactly. I can only guess. According to the documentation https://docs.liquibase.com/commands/utility/calculate-checksum.html, liquibase uses --changeset-author, --changeset-path and --changeset-id to compute the hash. Since author and id are the same, i can only assume that paths/files provided via --classpath are internally handled different than files provided via the search path. I didn't investigate further.