xml 变更日志文件中的 Liquibase "Cannot find the declaration of element 'databaseChangeLog'"

Liquibase "Cannot find the declaration of element 'databaseChangeLog'" in xml changeLog file

根据 Liquibase 官方网站的 This guide,我创建了自己的 changelog-master.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog"
               xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
    <includeAll path="/home/username/liquibase/examples/sqlite-test" filter="sql"/>
</databaseChangeLog>

然后我在同一文件夹中创建了 liquibase.properties 文件:

# Enter the path for your changelog file.
changeLogFile=changelog-master.xml

#### Enter the Target database 'url' information  ####
url=jdbc:sqlite://home/username/liquibase/examples/sqlite-test/testdb

这是正确的,因为如果我 运行 一个正常的 .sql 更新日志它 运行 正确并更新我的数据库。

然后我在 sql 中创建了一个更改日志文件,它必须在启动 liquibase update 时自动执行,即 000020-changelog.sql

--liquibase formatted sql

--changeset daniel:3
create table phonebook(name TEXT, surname TEXT, type TEXT, phone_number TEXT);

但是当我启动 liquibase update 时,XML 解析器出现错误:

Unexpected error running Liquibase: cvc-elt.1.a: Cannot find the declaration of element 'databaseChangeLog'.

而且我不明白问题出在哪里。我已经多次检查 changelog-master.xml 文件是否正确并且看起来是正确的。据我所知,cvc-elt.1.a 是一个 XML 解析错误,例如 databaseChangeLog 它未在 xml 模式中声明。

我这样做是为了将来我可以创建任意数量的变更日志,并让它们一个接一个地自动执行。

我一直在寻找这个问题的一些解决方案,但我找不到任何东西。我在官方论坛上找到了 link,但它现在已经死了 link。

额外信息:

08/09/2020 编辑:

如评论中所述,这是项目的结构:

root@dev-machine:/home/username/liquibase/examples/sqlite-test# ls -la
total 68
drwxr-xr-x 2 root    root     4096 Sep  4 17:28 .
drwxr-xr-x 5 username username  4096 Sep  4 17:02 ..
-rw-r--r-- 1 root    root      139 Sep  4 13:35 000020-changelog.sql
-rw-r--r-- 1 root    root      118 Sep  4 13:36 000030-changelog.sql
-rw-r--r-- 1 root    root      201 Sep  4 17:05 000040-changelog.sql
-rw-r--r-- 1 root    root      240 Sep  4 17:28 000050-changelog.sql
-rw-r--r-- 1 root    root      456 Sep  4 14:22 changelog-master.xml
-rw-r--r-- 1 root    root     2637 Sep  4 16:36 liquibase.properties
-rw-r--r-- 1 root    root    32768 Sep  4 17:28 testdb

testdb 是我用来测试 liquibase 的 sqlite 数据库。 .sql 文件是必须 运行 更新数据库的连续更新日志

导致我遇到问题的原因是,在我的 changelog-master.xml 中,我有一个过时的 XSD 版本,这导致某些东西侵入了 XML 解析器。为了修复它,我用以下内容更改了它:

<?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-4.0.xsd 
    http://www.liquibase.org/xml/ns/dbchangelog 
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
    ">
    <includeAll path="schema/"/>
</databaseChangeLog>

并将我所有的 *.sql 文件移动到 schema/ 文件夹中。除此之外,我使用 *.databasetype.sql 命名方案重命名了所有 .sql 文件,在我的例子中是 000020-changelog.sqlite.sql。必须这样做,否则使用 --liquibase formatted sql 的文件将不会被执行。

对我来说,这个问题与 httphttps 更相关。下面显示配置成功:

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"                 <-- NOT HTTPS!
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               <-- NOT HTTPS!
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog     <-- NOT HTTPS!
  https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
  <includeAll path="changelogs/" relativeToChangelogFile="true"/>
</databaseChangeLog>

如果将三行中任意一行的http改为https,则会抛出异常:

liquibase.exception.ChangeLogParseException: Error parsing line 6 column 70
of classpath:db/main.xml: cvc-elt.1.a: Cannot find the declaration of
element 'databaseChangeLog'.