Skip to content

sqlFile + relativeToChangelogFile fails when using a logicalFilePath #1277

@darkcamper

Description

@darkcamper

Environment

Liquibase Version: 4.0.0

Liquibase Integration & Version: CLI

Liquibase Extension(s) & Version:

Database Vendor & Version: SQL SERVER 2019

Operating System Type & Version: WIN 10 Pro 2004 (19041.388)

Description

When a changelog has a 'logicalFilePath' set, execution of 'sqlFile' changes that have the 'relativeToChangelogFile' set to true fail with an IOException that says that the sql file can't be found in a number of different paths. If 'logicalFilePath' is not set, everything works

Steps To Reproduce

  • Have a simple XML changelog that has an 'logicalFilePath' attribute in the root 'databaseChangeLog' node.
  • Have inside that changelog a changeset with a 'sqlFile' change that points to an existing file in the same folder than the changelog, and that has 'relativeToChangelogFile="true"'
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
    http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"
    logicalFilePath="a-logical-file-path">
   

<changeSet id="some-changeset" author="NA">
      <sqlFile endDelimiter="GO"
        path="file.sql"
        relativeToChangelogFile="true"
       />
</changeSet> 
</databaseChangeLog>
  • Run liquibase update against the db
liquibase --driver=com.microsoft.sqlserver.jdbc.SQLServerDriver --url="jdbc:sqlserver://localhost:1433;database=the_database" --changeLogFile=changelog.xml  --username=the_username --password=thepassword --logLevel=debug update

Actual Behavior

Executions fails with an IOException.

Unexpected error running Liquibase: java.io.IOException: The file file.sql was not found in
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\access-bridge-64.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\cldrdata.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\dnsns.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\jaccess.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\localedata.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\nashorn.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\sunec.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\sunjce_provider.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\sunmscapi.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\sunpkcs11.jar
    - C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre\lib\ext\zipfs.jar

...

Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
For more information, please use the --logLevel flag

Expected/Desired Behavior

No error happens and the sql file is executed against the database.

Additional Context

  • This is happening since 4.0.0 beta1. Version 3.10 works fine
  • Peeking a little inside the code, it seems that SQLFileChange.openSqlStream is using the filepath of the changeset (which contains the logicalFilePath) instead of the physical path of the containing changelog (which seems to be the behavior of v 3.x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions