Home > other >  Liquibase error when changeset uses runWith=sqlcmd
Liquibase error when changeset uses runWith=sqlcmd

Time:03-26

My environment is SQL Server 2019 and Liquibase 4.8.0

I'm having troubles using runWith=sqlcmd within a changeset. Liquibase responds with:

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

However, looking at the documentation, and the examples (near the bottom), here: https://docs.liquibase.com/concepts/changelogs/attributes/using-sqlcmd-integration.html

...it seems to be saying that the "runWith" attribute should be within the changeSet tag

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>

Check that sqlcmd is where I think it is:

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

sqlcmd_test.sql

DECLARE @foobat int;
GO

Trying it out...

####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  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 [email protected] 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```

CodePudding user response:

The short version is that you are pointing to out of date XSD files in the header of your XML Changelog file. You are pointing to some marked version 2.0 - which are super old and predate the capability.

At any point, the correct ones are in the examples folder under your Liquibase installation.

For reference, as of 4.8.0, the header in the example is:

<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 ">
  • Related