question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`relativeToChangeLogFile` not working with `SpringResource#resolveSibling`

See original GitHub issue

Environment

Liquibase Version: 4.17

Liquibase Integration & Version: Spring Boot 3.0.0-RC1

Operating System Type & Version: Windows 10

Description

Folder structure:

src/main/resources/db/changelog/
├── changelog.xml
└── data.csv

changelog.xml:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.5.xsd">

    <changeSet id="relative import" author="kzander91">
        <createTable tableName="my_table">
            <column name="test_col" type="bigint"/>
        </createTable>
        <loadData tableName="my_table"
                  file="data.csv"
                  relativeToChangelogFile="true">
            <column name="test_col" type="bigint"/>
        </loadData>
    </changeSet>

</databaseChangeLog>

The loadData change resolves file to /data.csv instead of /db/data.csv. This worked previously with 4.9.1 and broke with 4.17.0. The bug is located in SpringResource: https://github.com/liquibase/liquibase/blob/c9ceb05141eee992c7aaa3002451bb5f531b49d5/liquibase-core/src/main/java/liquibase/integration/spring/SpringResource.java#L40-L49

If resource is a org.springframework.core.io.UrlResource, createRelative() uses new URL(URL, String) to resolve the relative URL: https://github.com/spring-projects/spring-framework/blob/v6.0.0-RC2/spring-core/src/main/java/org/springframework/core/io/UrlResource.java#L310-L317

This effectively calls

new URL(new URL("file://C:/Temp/demo/target/classes/db/changelog/changelog.xml"), "../data.csv")

Which resolves to file://C:/Temp/demo/target/classes/db/data.csv instead of file://C:/Temp/demo/target/classes/db/changelog/data.csv.

Steps To Reproduce

  • Use <loadData relativeToChangelogFile="true"/>.
  • Start migration with Spring Boot.

Actual Behavior

Relative file is resolved incorrectly, migration aborts due to “unknown file”.

Expected/Desired Behavior

Relative paths are resolved correctly as before.

Reproducer

demo.zip

  • Unzip and run mvnw test, test fails.
  • Uncomment liquibase.version property in pom and rerun: test succeeds.

Possibly related

#3354 #3365 #3064

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
XDelphiGrlcommented, Dec 2, 2022

Hello, @OleksandrShkurat -

The 4.18.0 tag was added when we started our internal release process. Regressions were found which necessitated rework, but the tag in git was not removed during that time. We are still working to get the 4.18.0 release out. There are lots of boring, internal reasons this is the case, but I promise, we’re working on it. My apologies for the wait; I too, want to see this released!

-erzsebet (XDelphiGrl)

2reactions
OleksandrShkuratcommented, Dec 8, 2022

Thank you. I already updated my project yesterday

Read more comments on GitHub >

github_iconTop Results From Across the Web

relativeToChangeLogFile not working as documented
I run Liquibase from the parent directory of changelog , e.g. c:\MyProject> liquibase --changeLogFile=changelog\main.xml .... This worked fine ...
Read more >
Additional unfixed issues with relativeToChangelogfile + ...
In the Spring one, it works without any problem. But when running liquibase:status on Maven it shows me it would need to run...
Read more >
Liquibase doesn't load *.sql from classpath inside of changeSet
Solution is to change attribute for sqlFile tag: relativeToChangelogFile="false". Result changeSet below: <changeSet id="2" author="sergii" ...
Read more >
sqlFile should support relativeToChangelogFile parameter
I'm not sure if I tested that, it may be relative to the top level changelog, which isn't right. I'll take a look....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found