1

问题很简单:liquibase 找不到我的变更集 sqlfile 来针对我的数据库运行它。

路径如下:

  • SqlCl:C:\Oracle\sqlcl
  • 用户环境变量中没有定义 CLASSPATH
  • 主要变更日志文件:C:\repos\odb\db-scripts\main.yaml
  • 变更集 sqlfile:C:\repos\odb\db-scripts\test.sql

main.yaml 包含:

databaseChangeLog:

  - changeSet:
      id: 1
      author: some_author
      changes:
        - sqlFile:
            path: test.sql
            splitStatements: true
            endDelimiter: /
            stripComments: true

test.sql 包含:

create or replace view asdas
as
select 1 val from dual
/

当我通过 sqlcl 运行 liquibase 更新时得到什么:

C:\repos\odb\db-scripts>sql stat_adm@dev-odb1
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en

SQLcl: Release 20.4 Production on Tue May 25 18:03:50 2021

Copyright (c) 1982, 2021, Oracle.  All rights reserved.

Password? (**********?) ********
Last Successful login time: Tue May 25 2021 18:03:55 +03:00

Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.7.0.0.0


SQL> lb update -changelog main.yaml

Processing has failed for your request.
liquibase.exception.UnexpectedLiquibaseException: java.io.IOException: The file test.sql was not found in
    - C:\Oracle\jdbc\lib\ojdbc8.jar
    - C:\Oracle\jlib\orai18n-mapping.jar
    - C:\Oracle\jlib\orai18n-utility.jar
    - C:\Oracle\jlib\orai18n.jar
    - C:\Oracle\lib\ojdbc8.jar
    - C:\Oracle\modules\oracle.xdk\xmlparserv2.jar
    - C:\Oracle\rdbms\jlib\xdb6.jar
    - C:\Oracle\sqlcl\lib
    - C:\Oracle\sqlcl\lib\ST4.jar
    - C:\Oracle\sqlcl\lib\antlr-runtime.jar
    - C:\Oracle\sqlcl\lib\commons-codec.jar
    - C:\Oracle\sqlcl\lib\commons-logging.jar
    - C:\Oracle\sqlcl\lib\dbtools-common.jar
    - C:\Oracle\sqlcl\lib\dbtools-data.jar
    - C:\Oracle\sqlcl\lib\dbtools-http.jar
    - C:\Oracle\sqlcl\lib\dbtools-net.jar
    - C:\Oracle\sqlcl\lib\dbtools-sqlcl.jar
    - C:\Oracle\sqlcl\lib\ext
    - C:\Oracle\sqlcl\lib\ext\dbtools-liquibase.jar
    - C:\Oracle\sqlcl\lib\ext\dbtools-modeler-cli-ext.jar
    - C:\Oracle\sqlcl\lib\ext\dbtools-modeler-common.jar
    - C:\Oracle\sqlcl\lib\ext\liquibase-core.jar
    - C:\Oracle\sqlcl\lib\ext\migration-core.jar
    - C:\Oracle\sqlcl\lib\ext\migration-postgres.jar
    - C:\Oracle\sqlcl\lib\ext\snakeyaml-1.12.jar
    - C:\Oracle\sqlcl\lib\guava.jar
    - C:\Oracle\sqlcl\lib\httpclient.jar
    - C:\Oracle\sqlcl\lib\httpcore.jar
    - C:\Oracle\sqlcl\lib\httpmime.jar
    - C:\Oracle\sqlcl\lib\jackson-annotations.jar
    - C:\Oracle\sqlcl\lib\jackson-core.jar
    - C:\Oracle\sqlcl\lib\jackson-jr-objects.jar
    - C:\Oracle\sqlcl\lib\jackson-jr-stree.jar
    - C:\Oracle\sqlcl\lib\jansi.jar
    - C:\Oracle\sqlcl\lib\javax.json.jar
    - C:\Oracle\sqlcl\lib\jdbcrest.jar
    - C:\Oracle\sqlcl\lib\jline.jar
    - C:\Oracle\sqlcl\lib\ojdbc8.jar
    - C:\Oracle\sqlcl\lib\oraclepki.jar
    - C:\Oracle\sqlcl\lib\orai18n-collation.jar
    - C:\Oracle\sqlcl\lib\orai18n-mapping.jar
    - C:\Oracle\sqlcl\lib\orai18n-servlet.jar
    - C:\Oracle\sqlcl\lib\orai18n-utility.jar
    - C:\Oracle\sqlcl\lib\orai18n.jar
    - C:\Oracle\sqlcl\lib\orajsoda.jar
    - C:\Oracle\sqlcl\lib\osdt_cert.jar
    - C:\Oracle\sqlcl\lib\osdt_core.jar
    - C:\Oracle\sqlcl\lib\slf4j-api.jar
    - C:\Oracle\sqlcl\lib\slf4j-jdk14.jar
    - C:\Oracle\sqlcl\lib\sshd-common.jar
    - C:\Oracle\sqlcl\lib\sshd-contrib.jar
    - C:\Oracle\sqlcl\lib\sshd-core.jar
    - C:\Oracle\sqlcl\lib\xdb6.jar
    - C:\Oracle\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar
    - C:\Oracle\sqlcl\lib\xmlparserv2.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\access-bridge-64.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\cldrdata.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\dnsns.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\jaccess.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\jfxrt.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\localedata.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\nashorn.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunec.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunjce_provider.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunmscapi.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunpkcs11.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\zipfs.jar
    - C:\jdbc\lib\ojdbc8.jar
    - C:\jlib\orai18n-mapping.jar
    - C:\jlib\orai18n-utility.jar
    - C:\jlib\orai18n.jar
    - C:\rdbms\jlib\xdb6.jar
    - C:\repos\odb\db-scripts\ST4-4.3.1.jar
    - C:\repos\odb\db-scripts\antlr-runtime-3.5.2.jar
    - C:\repos\odb\db-scripts\commons-codec-1.15.jar
    - C:\repos\odb\db-scripts\commons-logging-1.2.0.0.1.jar
    - C:\repos\odb\db-scripts\dbtools-common-20.4.1.jar
    - C:\repos\odb\db-scripts\dbtools-data-20.4.1.jar
    - C:\repos\odb\db-scripts\dbtools-http-20.4.1.jar
    - C:\repos\odb\db-scripts\dbtools-net-20.4.1.jar
    - C:\repos\odb\db-scripts\dbtools-sqlcl-20.4.1.jar
    - C:\repos\odb\db-scripts\guava-30.0-jre.jar
    - C:\repos\odb\db-scripts\httpclient-4.5.13.jar
    - C:\repos\odb\db-scripts\httpcore-4.4.13.jar
    - C:\repos\odb\db-scripts\httpmime-4.5.13.jar
    - C:\repos\odb\db-scripts\jackson-annotations-2.11.3.jar
    - C:\repos\odb\db-scripts\jackson-core-2.11.3.jar
    - C:\repos\odb\db-scripts\jackson-jr-objects-2.11.3.jar
    - C:\repos\odb\db-scripts\jackson-jr-stree-2.11.3.jar
    - C:\repos\odb\db-scripts\jansi-1.18.jar
    - C:\repos\odb\db-scripts\javax.activation-api-1.2.0.jar
    - C:\repos\odb\db-scripts\javax.json-1.1.4.jar
    - C:\repos\odb\db-scripts\jaxb-api-2.4.0-b180830.0359.jar
    - C:\repos\odb\db-scripts\jdbcrest-20.4.1.jar
    - C:\repos\odb\db-scripts\jline-2.14.6.jar
    - C:\repos\odb\db-scripts\low-level-api-13.0.0.jar
    - C:\repos\odb\db-scripts\ojdbc8-21.0.0.jar
    - C:\repos\odb\db-scripts\oraclepki-21.0.0.jar
    - C:\repos\odb\db-scripts\orai18n-21.0.0.jar
    - C:\repos\odb\db-scripts\orai18n-mapping-21.0.0.jar
    - C:\repos\odb\db-scripts\orai18n-utility-21.0.0.jar
    - C:\repos\odb\db-scripts\orajsoda-1.1.3.jar
    - C:\repos\odb\db-scripts\osdt_cert-21.0.0.jar
    - C:\repos\odb\db-scripts\osdt_core-21.0.0.jar
    - C:\repos\odb\db-scripts\slf4j-api-1.7.30.jar
    - C:\repos\odb\db-scripts\slf4j-jdk14-1.7.30.jar
    - C:\repos\odb\db-scripts\sshd-common-2.5.0.jar
    - C:\repos\odb\db-scripts\sshd-contrib-2.5.0.jar
    - C:\repos\odb\db-scripts\sshd-core-2.5.0.jar
    - C:\repos\odb\db-scripts\sshd-scp-2.5.0.jar
    - C:\repos\odb\db-scripts\sshd-sftp-2.5.0.jar
    - C:\repos\odb\db-scripts\ucp-21.0.0.jar
    - C:\repos\odb\db-scripts\xdb6-21.0.0.jar
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.

SQL>

不知何故,它选择了C:\repos\odb\db-scripts\路径,但只是想象中的罐子不会在那里持续存在。顺便说一下C:\jdbc\lib\,我的机器C:\jlib\C:\rdbms\jlib\xdb6.jar甚至都不存在路径。

添加relativeToChangelogFile: truemain.yaml没有帮助。

我应该如何告诉从当前目录中sqlcl获取test.sql文件或至少提供完整路径?

编辑:

我决定自己运行它liquibase。我下载了 liquibase 安装 zip 存档并liquibase.bat从中取出并将其放入sqlcl安装路径。然后我将此路径添加到我的PATH变量中,以便我可以从命令行调用它。

我还在C:\repos\odb\db-scripts\文件liquibase.properties中创建了以下内容:

changeLogFile: main.yaml
driver: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@mega-db-host:1521/odb1
username: usr
password: pwd

请注意,和C:\repos\odb\db-scripts\的目录相同。之后我运行了 liquibase:test.sqlmain.yaml

C:\repos\odb\db-scripts>liquibase update
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##  Get advanced features and support at          ##
##      liquibase.com/support                     ##
##                                                ##
####################################################
Starting Liquibase at 10:11:50 (version 4.1.1 #0 built at 2020-11-02 16:02+0000)
ScriptRunner Executing: create or replace view asdas
as
select 1 val from dualLiquibase Executed:create or replace view asdas
as
select 1 val from dual
Liquibase: Update has been successful.

请参阅:没有错误。之后,我决定将不存在的路径设置为 sql 文件并猜测我得到了什么:

C:\repos\odb\db-scripts>liquibase update
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##  Get advanced features and support at          ##
##      liquibase.com/support                     ##
##                                                ##
####################################################
Starting Liquibase at 10:12:44 (version 4.1.1 #0 built at 2020-11-02 16:02+0000)
Unexpected error running Liquibase: java.io.IOException: The file not_exists.sql was not found in
    - C:\Oracle\sqlcl\lib
    - C:\Oracle\sqlcl\lib\ST4.jar
    - C:\Oracle\sqlcl\lib\antlr-runtime.jar
    - C:\Oracle\sqlcl\lib\commons-codec.jar
    - C:\Oracle\sqlcl\lib\commons-logging.jar
    - C:\Oracle\sqlcl\lib\dbtools-common.jar
    - C:\Oracle\sqlcl\lib\dbtools-data.jar
    - C:\Oracle\sqlcl\lib\dbtools-http.jar
    - C:\Oracle\sqlcl\lib\dbtools-net.jar
    - C:\Oracle\sqlcl\lib\dbtools-sqlcl.jar
    - C:\Oracle\sqlcl\lib\ext\dbtools-liquibase.jar
    - C:\Oracle\sqlcl\lib\ext\dbtools-modeler-cli-ext.jar
    - C:\Oracle\sqlcl\lib\ext\dbtools-modeler-common.jar
    - C:\Oracle\sqlcl\lib\ext\liquibase-core.jar
    - C:\Oracle\sqlcl\lib\ext\migration-core.jar
    - C:\Oracle\sqlcl\lib\ext\migration-postgres.jar
    - C:\Oracle\sqlcl\lib\ext\snakeyaml-1.12.jar
    - C:\Oracle\sqlcl\lib\guava.jar
    - C:\Oracle\sqlcl\lib\httpclient.jar
    - C:\Oracle\sqlcl\lib\httpcore.jar
    - C:\Oracle\sqlcl\lib\httpmime.jar
    - C:\Oracle\sqlcl\lib\jackson-annotations.jar
    - C:\Oracle\sqlcl\lib\jackson-core.jar
    - C:\Oracle\sqlcl\lib\jackson-jr-objects.jar
    - C:\Oracle\sqlcl\lib\jackson-jr-stree.jar
    - C:\Oracle\sqlcl\lib\jansi.jar
    - C:\Oracle\sqlcl\lib\javax.activation-api.jar
    - C:\Oracle\sqlcl\lib\javax.json.jar
    - C:\Oracle\sqlcl\lib\jaxb-api.jar
    - C:\Oracle\sqlcl\lib\jdbcrest.jar
    - C:\Oracle\sqlcl\lib\jline.jar
    - C:\Oracle\sqlcl\lib\low-level-api.jar
    - C:\Oracle\sqlcl\lib\ojdbc8.jar
    - C:\Oracle\sqlcl\lib\oraclepki.jar
    - C:\Oracle\sqlcl\lib\orai18n-mapping.jar
    - C:\Oracle\sqlcl\lib\orai18n-utility.jar
    - C:\Oracle\sqlcl\lib\orai18n.jar
    - C:\Oracle\sqlcl\lib\orajsoda.jar
    - C:\Oracle\sqlcl\lib\osdt_cert.jar
    - C:\Oracle\sqlcl\lib\osdt_core.jar
    - C:\Oracle\sqlcl\lib\slf4j-api.jar
    - C:\Oracle\sqlcl\lib\slf4j-jdk14.jar
    - C:\Oracle\sqlcl\lib\snakeyaml-1.12.jar
    - C:\Oracle\sqlcl\lib\sshd-common.jar
    - C:\Oracle\sqlcl\lib\sshd-contrib.jar
    - C:\Oracle\sqlcl\lib\sshd-core.jar
    - C:\Oracle\sqlcl\lib\sshd-scp.jar
    - C:\Oracle\sqlcl\lib\sshd-sftp.jar
    - C:\Oracle\sqlcl\lib\ucp.jar
    - C:\Oracle\sqlcl\lib\xdb6.jar
    - C:\Oracle\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\access-bridge-64.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\cldrdata.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\dnsns.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\jaccess.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\jfxrt.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\localedata.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\nashorn.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunec.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunjce_provider.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunmscapi.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\sunpkcs11.jar
    - C:\Program Files\Java\jre1.8.0_271\lib\ext\zipfs.jar
    - C:\repos\odb\db-scripts
    - C:\repos\odb\db-scripts\.
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

请注意,liquibase 在查找列表中添加了当前目录。这就是它设法找到我的test.sql文件的原因。看起来sqlcl是一个未能使用 SQL 文件的当前路径的人。

4

0 回答 0