2
votes

I have the following changeset, using LiquiBase 3.5.1 (latest):

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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-3.5.xsd">

    <preConditions onFail="MARK_RAN">
        <sqlCheck expectedResult="2">SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo';</sqlCheck>
    </preConditions>
    <changeSet author="user" id="base">
        <sqlFile path="liquibase/base.sql"/>
    </changeSet>
</databaseChangeLog>

Seems simply enough, right? The idea is that it checks to see if the DB is empty (checking for 2 tables for the Liquibase tables that are auto-generated) and if it is, run a base script. If it fails, however, it is supposed to mark the changeset as run and move along (documentation for the feature here). However, I get the following error:

Value 'MARK_RAN' is not facet-valid with respect to enumeration '[HALT, WARN]'.
1
Checkout my answer here. Short answer: MARK_RAN is not available on the changelog level. Only on changesets. - Jens

1 Answers

2
votes

Liquibase distinguishes between preconditions at the changelog level and Preconditions at the changeset level. Outside a changeset (e.g. at the beginning of the change log), only HALT and WARN are possible values.

Look at the xsd schema

There are two Types: onChangeSetPreconditionErrorOrFail and onChangeLogPreconditionErrorOrFail

You can just change your script as follows:

<changeSet author="user" id="base">
    <preConditions onFail="MARK_RAN">
    <sqlCheck expectedResult="2">SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo';</sqlCheck>
    </preConditions>
    <sqlFile path="liquibase/base.sql"/>
</changeSet>