Search code examples
springpostgresqlspring-bootliquibasechecksum

Force liquibase to calculate checksum by the given parameters values


In my yaml I have a parameter structure like this:

spring:
  liquibase:
    parameters:
      tables:
        table1: table1

and a script which creates virtual tables in PostgreSQL based on a database object.

CREATE FOREIGN TABLE my_table1 (
 ...
)
SERVER server_object
OPTIONS (schema_name 'common', table_name '${tables.table1}');

As far as I know checksum calculation is based on the given text not the substituted value.

My question is what are the possibilities to acquire the recently mentioned one, so that when I change from table1 to table2 for example and run the program, Liquibase will throw an error due to changed parameter value.

I have heard about preConditions but I think that's not what I'm looking for or validCheckSum which is perhaps an even more distant thought.

UPDATE

<changeSet author="user1" id="create_virtual_tables" dbms="postgresql">
    <sqlFile path="liquibase/sql/ddl/virtual_tables.sql"/>
</changeSet>
CREATE FOREIGN TABLE public.games (
    id SERIAL PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    genre VARCHAR(100),
    release_date DATE,
    developer VARCHAR(255)
)
SERVER remote_server
OPTIONS (schema_name '${remote.schema.name}', table_name '${remote.table.games_table}');

Solution

  • The behaviour you are observing is actually in sync with documentation:

    sql and sqlFile

    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.

    So, basically, in order to get desired behaviour you need to inline your sql into changeset and use <sql> change instead of sqlFile change.