15

I'm trying to execute the following changeSet in liquibase which should create an index. If the index doesn't exist, it should silently fail:

<changeSet failOnError="false" author="sys" id="1">
    <createIndex unique="true"  indexName="key1" tableName="Table1">
        <column name="name" />
    </createIndex>
</changeSet>

So far, so good. The Problem is, that this changeSet doesn't get logged into DATABASECHANGELOG table and is therefor executed every time liquibase runs. According to the liquibase documentation and e.g. this answer from Nathen Voxland i thought that the changeset should be marked as ran in the DATABASECHANGELOG table. Instead it isn't logged at all and as i said before executed every time liquibase runs (and fails everytime again).

Am i missing something?

(I'm using MySQL as DBMS)

Community
  • 1
  • 1
ebi
  • 325
  • 1
  • 3
  • 8

1 Answers1

11

In the answer given by Nathen Voxland, he recommended the more correct approach of using a precondition to check the state of the database, before running the changeset.

It seems to me that ignoring a failure is a bad idea.... Means you don't fully control the database configuration.... The "failOnError" parameter allows liquibase to continue. Wouldn't it be a bad idea for a build to record a changset as executed, if in fact it didn't because an error occurred?

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • I'm totally with you, using a precondition is the right approach in my opinion too. After all, that's what i did with my `changeSet` (although uniqueConstraintExists precondition is missing, but that's another fact). I just stumbled upon my expectations of the `failOnError="false"` attribute and I asked myself if the described behavior is a bug or a feature ;) – ebi Jun 07 '12 at 07:55
  • 1
    Unfortunately a precondition for Oracle non-null doesn't work for me because checking for a non-nullable column isn't supported by liquibase. – sf_jeff Sep 28 '15 at 16:49
  • I am posting this on behalf of [dev-null](https://stackoverflow.com/users/1436741/dev-null) who has posted this comment as an answer; _This is relateted to the comment of st_jeff in the preceding answer (but I have no 50 reputation to make a comment): Another use case for failOnError: If you drop an unique constraint in oracle, than the related index gets only droped if it's newer than the constraint. So a drop index statement after dropping the constraint may result in an error or not, depending on the age of the index._ – Bugs Jun 01 '17 at 11:32