变更集使用 runWith=sqlcmd 时出现 Liquibase 错误

Liquibase error when changeset uses runWith=sqlcmd

我的环境是 SQL Server 2019 和 Liquibase 4.8.0

我在变更集中使用 runWith=sqlcmd 时遇到问题。 Liquibase 回复:

Attribute 'runWith' is not allowed to appear in element 'changeSet'

但是,查看此处的文档和示例(靠近底部): https://docs.liquibase.com/concepts/changelogs/attributes/using-sqlcmd-integration.html

...好像是说“runWith”属性应该在changeSet标签​​内

liquibase.properties

classpath=C:\Program Files\Microsoft SQL Server\sqljdbc_10.2\enu\mssql-jdbc-10.2.0.jre8.jar
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://localhost:1433;database=SSReporting;Enlist=false
liquibaseSchemaName=dbo
username=deploy_dbbuild
password=xxxxxxx
changeLogFile=changelog.xml
liquibase.hub.mode=off
integratedSecurity=false
liquibase.sqlcmd.args=-v db_to_use=SSReporting
liquibase.sqlcmd.keep.temp=true
liquibase.sqlcmd.keep.temp.name=liq.log
liquibase.sqlcmd.path=C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn
liquibase.sqlcmd.timeout=-1

changelog.xml

<?xml version="1.0" encoding="UTF-8"?>
<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
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd" >

        <changeSet id="sqlcmd_test" runWith="sqlcmd" runOnChange="true" author="smcintosh" >
                <sqlFile path="sqlcmd_test.sql" relativeToChangelogFile="true" />
        </changeSet>
</databaseChangeLog>

检查 sqlcmd 是否在我认为的位置:

C:\> where sqlcmd
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn\SQLCMD.EXE

sqlcmd_test.sql

DECLARE @foobat int;
GO

正在尝试...

####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 13:53:48 (version 4.8.0 #1581 built at 2022-02-18 21:43+0000)
Liquibase Version: 4.8.0
Liquibase Pro 4.8.0 by Liquibase licensed to Liquibase Pro Evaluation until Tue Mar 29 19:00:00 EDT 2022
WARNING!  Your license will expire in 5 days!
To renew Liquibase Pro please contact sales@liquibase.com or go to https://www.liquibase.org/download

Unexpected error running Liquibase: Error parsing line 8 column 86 of changelog.xml: cvc-complex-type.3.2.2: Attribute 'runWith' is not allowed to appear in element 'changeSet'.

For more information, please use the --log-level flag```

简而言之,您在 XML 更新日志文件的 header 中指向了过时的 XSD 文件。您指的是一些标记为 2.0 的版本 - 非常旧并且早于该功能。

在任何时候,正确的都在您的 Liquibase 安装下的 examples 文件夹中。

供参考,自 4.8.0 起,示例中的 header 为:

<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">