spring-bootliquibaseliquibase-sql

Liquibase executing sql script even if dbms is set


I'm trying to use Liquibase for different db vendors and for each one of them I have different sql scripts.

What I was trying to do is this:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.10.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">
    <includeAll path="oracleLiquibase" />
    <includeAll path="postgresql" />
    <includeAll path="sqlserver" />
    <includeAll path="mysql" />
</databaseChangeLog>

In these folders I have each sql file to be executed but with the dbms property set, since I cannot add the dbms property on the includeAll tag.

As an example, two sql files for 2 different db vendors look like this:

FunctionFile.sql (for postgresql)

-- liquibase formatted sql

-- changeset ion.grigoras:myFunction dbms=postgresql
CREATE OR REPLACE FUNCTION myFunction(...)
 RETURNS BIGINT
 LANGUAGE plpgsql
AS $function$
    declare
        -- vars;
    BEGIN
        -- body;
    END;
$function$;

FunctionFile.sql (for oracle)

--liquibase formatted sql

-- changeset ion.grigoras:myFunction dbms=oracle
CREATE OR REPLACE function myFunction(...) return NUMBER is
BEGIN
  -- body;
END;
/

I'm launching a Spring boot application and I'm using an oracle datasource so I'm expecting only the FuntionFile.sql for oracle to be executed, but what I see in the logs is that a changeset has failed and that changeset was from a sql file for postresql.

I don't understand why is postgresql being executed since I set the dbms property for each changeset in the fomatted sql files.

I would definitely like to avoid the use of <sqlFile /> on the changelog.xml file since I have a moderated number of files for each db vendor, keeping them separate in different folders and using <includeAll /> is the perfect scenario in my opinion.


Solution

  • I'm not very familiar with SQL notation, but I believe you have an error in your changeSet syntax. Attributes should be separated by : from it's values, according to the documentation:

    --changeset author:id attribute1:value1 attribute2:value2 [...]

    So I'd try the following syntax:

    -- changeset ion.grigoras:myFunction dbms:postgresql

    and

    -- changeset ion.grigoras:myFunction dbms:oracle