Not ( uniqueConstraintExists ) not working

I have the following changeset with precondition

<changeSet author="avmakarov" id="2023.10.18_1021_AddProductCodeUniq (1)">
        <preConditions onFail="MARK_RAN">
                <uniqueConstraintExists tableName="LC_PRODUCT" constraintName="LC_PRODUCT_UN1"/>
        <addUniqueConstraint tableName="LC_PRODUCT" columnNames="CODE" constraintName="LC_PRODUCT_UN1"/>

I’ve run it on clean base and it did not append uniquie constraint

10:23:45.521 [] Info  liquibase.ui - Running Changeset: db/2023.10.18_1021_AddProductCodeUniq.xml::2023.10.18_1021_AddProductCodeUniq (1)::avmakarov
10:23:45.647 [] Info  liquibase.changelog - Marking ChangeSet: "db/2023.10.18_1021_AddProductCodeUniq.xml::2023.10.18_1021_AddProductCodeUniq (1)::avmakarov" as ran despite precondition failure due to onFail='MARK_RAN': 
          db/liquibase-changeLog.xml : Not precondition failed

I dont find any topic about this problem so, is there some mistake?

We have been using this precondition without any problems, it is executed correctly both if the constraint already exists and if it does not exist.

The code looks quite similar, only difference is that we use yaml format, and that we also specify the schemaName both in the changeset and the precondition. We are using version 4.27.0.

Hi guys,

I tried with the below changelog on latest version as well:

<changeSet author="XYZ" id="1">
        <createTable tableName="car">
            <column name="id" type="INTEGER">
                <constraints nullable="false" primaryKey="true" primaryKeyName="actor_pkey"/>
            <column name="vendor" type="VARCHAR(255)"/>

    <changeSet author="mallod" id="AddCarUniqC">
        <preConditions onFail="MARK_RAN">
                <uniqueConstraintExists tableName="car" constraintName="car_UN1"/>
        <addUniqueConstraint tableName="car" columnNames="vendor" constraintName="car_UN1"/>

And both changesets were successfully executed, so I guess the error is not in the precondition. Might it be possible your unique constraint was already created in your DB?



It is working for random name.
I found error: the query that executed for search constraint dont use liquibaseSchema property.
Our postgres instance contains several schemas for our soft. So search index without schemaName found objects in other schemas.

Bear regards.

Hi @Bostandyksoft,

Oh, I see. If that’s the case would you mind creating a GH issue for it? If you are keen to fix it you can create a PR for it, if you have any question me or someone from the team can assist you.

Thanks in advance,