Search code examples
liquibase

Does Liquibase calc checksums for changesets before or after applying property substitution when using XML only?


I have the following changeset and can't find any docs about if the checksum is calculated before or after the property is substituted.

<changeSet author="[...]" id="[...]">
    <addColumn tableName="FOO">
        <column name="BAR" type="${type.string.max.80}" />
    </addColumn>
</changeSet>

Though, there might be a difference because for SQL embedded into XML and YAML things are differently handled compared to e.g. external SQL files. But in my case I don't have any plain SQL at all.

You can use property substitution with the sql and sqlFile Change Types. Note that Liquibase obtains the checksum of a sql changeset after substituting any properties you specify. However, it obtains the checksum of a sqlFile changeset before substituting the properties in the external SQL file.

https://docs.liquibase.com/concepts/changelogs/property-substitution.html?_ga=2.45579489.475291501.1716446628-689967727.1694174943

So what's the case for my XML-example?

Thanks!


Solution

  • If I get your question right and although it's not specified in the docs, if we make and experiment with a spring-boot app and create a changeSet like:

    <changeSet id="foo" author="bar">
        <createTable tableName="${test1}">
            <column name="the_name" type="varchar(32)"/>
        </createTable>
    </changeSet>
    

    where in application.properties we have:

    spring.liquibase.parameters.test1=12345
    

    Liquibase will create a table '12345'. And leave a record in the databasechangelog table with some checksum.

    Now if we change the test1 value to:

    spring.liquibase.parameters.test1=123456789
    

    and redeploy the application, Liquibase will fail with checksum validation error.

    So I'd suggest that Liquibase calculates checksum of xml changeSet AFTER applying property substitution but BEFORE executing the changeSet.

    Otherwise (from the checksum's perspective) the changeSet should've remained "the same" with tableName="${test1}" regardless of the property change.