Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase: How to drop unique constraint with no constraint name?

Tags:

java

liquibase

This is what my column looks like

        <column name="name" type="VARCHAR(255)">
            <constraints nullable="false" unique="true"/>
        </column>

I want to remove unique=true constraint.

I looked at what liquibase has to offer and it has

<changeSet author="liquibase-docs" id="dropUniqueConstraint-example">
    <dropUniqueConstraint catalogName="cat"
            constraintName="const_name"
            schemaName="public"
            tableName="person"
            uniqueColumns="A String"/>
</changeSet>

Now since constraintName is required and I do not have it, what are my options?

How can I drop unique=true using liquibase?

like image 540
daydreamer Avatar asked Jul 21 '14 18:07

daydreamer


1 Answers

I ended up creating a new column to replace the column that has the unique constraint.

<addColumn tableName="TABLE" schemaName="SCHEMA">
<column name="NEW_COLUMN" type="TYPE" valueComputed="OLD_COLUMN"></column>
</addColumn>

<dropColumn tableName="TABLE" schemaName="SCHEMA" columnName="OLD_COLUMN"/>

<renameColumn tableName="TABLE" schemaName="SCHEMA" oldColumnName="NEW_COLUMN" newColumnName="OLD_COLUMN"/>
like image 93
Dan Bradley Avatar answered Sep 28 '22 03:09

Dan Bradley