quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.62k stars 2.64k forks source link

Native Image run issue with XML Changelog quarkus-liquibase #42143

Closed RafiIsaharov closed 2 months ago

RafiIsaharov commented 2 months ago

I'm facing an issue with quarkus-liquibase, particularly with the XML Changelog. I noticed an issue on GitHub, which can be found at https://github.com/quarkusio/quarkus/issues/27437, opened in 2022.

Configuration:

quarkus.liquibase.enabled=true
quarkus.liquibase.migrate-at-start=true
quarkus.liquibase.change-log=db/postgres/changelog-master.yml

files : https://github.com/RafiIsaharov/esb-infra/tree/main/src/main/resources/db/postgres

Snapshot of changelog-master.yml:

databaseChangeLog:
  - include:
      file: db/postgres/changelog.001.sql
  - include:
      file: db/postgres/changelog.002.xml
  - include:
      file: db/postgres/changelog.003.sql
  - include:
      file: db/postgres/changelog.004.sql

Snapshot of changelog.002.xml:

<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 https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">

    <!--changeSet id="1" author="rafi.isaharov">
        <sql>
            ALTER TABLE routes ADD COLUMN timestamp TIMESTAMP;
        </sql>
    </changeSet-->

    <!--changeSet id="2" author="rafi.isaharov">
        <sql>
            ALTER TABLE routes ALTER COLUMN timestamp SET DEFAULT NOW();
        </sql>
    </changeSet-->

    <changeSet id="3" author="rafi.isaharov">
        <sql splitStatements="false">
            <![CDATA[
            -- Create a function to update timestamp on every update
            CREATE OR REPLACE FUNCTION update_timestamp()
            RETURNS TRIGGER AS $$
            BEGIN
                NEW.timestamp = NOW();
            RETURN NEW;
            END;
            $$ LANGUAGE plpgsql;
            ]]>
        </sql>
    </changeSet>

    <changeSet id="4" author="rafi.isaharov">
        <sql splitStatements="false">
            <![CDATA[
            -- Create a trigger to execute update_timestamp function on every update
            CREATE TRIGGER update_routes_timestamp
                BEFORE UPDATE ON routes
                FOR EACH ROW
                EXECUTE FUNCTION update_timestamp();
            ]]>
        </sql>
    </changeSet>

Error Trace: exception_liquibase_using_changelog_as_xml.txt

Observations:

Current Workaround: To overcome the issue with the XML changelog file, I am converting it into an equivalent SQL file format.

Reproduce the issue: I've uploaded the code to my GitHub repository, which includes the docker-compose.yaml file for the Postgres database. You can download and replicate it from the main branch https://github.com/RafiIsaharov/esb-infra.git.

quarkus-bot[bot] commented 2 months ago

/cc @andrejpetras (liquibase), @geoand (liquibase), @gsmet (liquibase), @zakkak (native-image)

gsmet commented 2 months ago

@gcw-it could you have a look at this one while you're at it? Maybe it's already fixed by your ongoing PRs?

gcw-it commented 2 months ago

@RafiIsaharov You're in luck. PR #41928 fixes your issue. I could reproduce your problem, and with the PR included your application started without problems and ran the Liquibase migrations successfully.

The answer to when the patch will be incorporated into a Quarkus release, will have to be given by @gsmet .

geoand commented 2 months ago

It should be part of the next 3.13 release

gsmet commented 2 months ago

Yeah so not 3.13.0 but 3.13.1 released in two weeks.

gsmet commented 2 months ago

@gcw-it thanks for checking!

geoand commented 2 months ago

Thanks again @gcw-it for this important fix!

gcw-it commented 2 months ago

@gsmet @geoand You're welcome!