Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase changeSet with failOnError="false" are always ran?

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)

like image 672
ebi Avatar asked Jun 06 '12 11:06

ebi


People also ask

How does Liquibase generate checksum?

When running the calculate-checksum command, the DATABASECHANGELOG table calculates an MD5 checksum for each entry based on the SQL script of the changeset. This checksum helps Liquibase detect differences between the changesets you want to deploy and the changesets that have already been run against the database.

How do Liquibase changelogs work?

Liquibase uses a changelog to sequentially list all changes made to your database. Think of it as a ledger. It is a file that contains a record of all your database changes (changesets). Liquibase uses this changelog record to audit your database and execute any changes that are not yet applied to your database.

Where does Liquibase store checksum?

what was actually run against the database, Liquibase stores a checksum with each changeset entry in the DATABASECHANGELOG tracking table.


1 Answers

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?

like image 58
Mark O'Connor Avatar answered Sep 28 '22 01:09

Mark O'Connor