Search code examples
postgresqlliquibase

Liquibase preconditions not working


I'm trying to use liquibase to track changes to a postgresql database using dropwizard-migrations. I'd like to be able to run the migration on the existing production database instead of rebuilding from scratch. Right now I'm testing in staging. I've created a changeset with a precondition.

<changeSet id="3" author="me">
    <preConditions onFail="CONTINUE">
        <not>
            <sequenceExists sequenceName="emails_id_seq"/>
        </not>
    </preConditions>
    <createSequence sequenceName="emails_id_seq" startValue="1" incrementBy="1" />
</changeSet>

My goal is to skip applying the changeset if the sequence is already there. Seems straightforward, but it's not working.

ERROR [2013-09-13 22:19:22,564] liquibase: Change Set migrations.xml::3::me failed.  Error: Error executing SQL CREATE SEQUENCE emails_id_seq START WITH 1 INCREMENT BY 1: ERROR: relation "emails_id_seq" already exists
! liquibase.exception.DatabaseException: Error executing SQL CREATE SEQUENCE emails_id_seq START WITH 1 INCREMENT BY 1: ERROR: relation "emails_id_seq" already exists

I've tried using the MARK_RAN instead of CONTINUE too. No luck with that.


Solution

  • I solved this by running the dropwizard-migrations "fast-forward" command as follows:

    java -jar hello-world.jar db fast-forward helloworld.yml
    

    This will mark the next changeset as applied without actually applying it. You may have to do this one time per changeset you want to fast-forward. There is also an --all flag if you want to fast forward everything.

    More details can be found here: http://dropwizard.codahale.com/manual/migrations/