Question: Precondition for uniqueConstraintExists or...

Short Version I’m looking for a uniqueConstraintExists precondition, or something that will accomplish the scenario below.

I’m switching from an unmanaged database (previously schema generated by JPA provider) to one managed by liquibase to help developer onboarding and ease migration.  For the existing schema, I simply added preconditions that will get onFail=“MARK_RAN” when the elements already exist.  I don’t want to do this for any new elements. 

  • Developers needs to support the liquibase -> construct brand new empty DB
  • Production,stage,test needs to support the liquibase -> continue where we left off the schema for all new changes

The problem I’m having is that in the pre-liquibase schema, there are unique constraints.  There isnt’ a precondition that I could check for existence and then just not run them.  I see three options:

  1. Don’t use liquibase to create the unique constrain on the old data
  2. write a custom precondition
  3. fabricate a ran changeset that include the unique constraint in the product,testing, databasechangelog table.

Any other options?  Am I missing a uniqueConstraintExists precondition?

I’m using:
liquibase 1.9.5.0
PostgreSQL 8.4.3

Thanks in advance!

You are right that there isn’t a uniqueConstraintExists precondion.  There is an indexExists precondition that may work since most databases will create a same-named index, but that is a bit of a stretch.

There is the generateChangeLog command which is designed to allow you get a starting changeLog for an existing database.  You will probably need to modify it a bit due to limitations of the underlying diff tool, but it could help with option #3 for you.

There is also an precondition which you may be able to use to query the information_schema for your unique constraint.  If you have a lot, however, it would be more readable and less error prone to write your own precondition to wrap that logic.

Nathan

I can attest to