Horace Heaven
Horace Heaven

Reputation: 710

How to create composite index in liquibase

How do I create a composite index using liquibase?

This is what I have so far:

    <createIndex indexName="idx_value"
                 tableName="test">
        <column name="value"/>
    </createIndex>

I have the following in mind, but I just need to confirm.

<createIndex indexName="idx_value"
             tableName="test">
    <column name="value0"/>
    <column name="value1"/>
</createIndex>

Upvotes: 12

Views: 15894

Answers (2)

Tacsiazuma
Tacsiazuma

Reputation: 776

For me that solution didn't work. It created separate indexes on the fields.

Instead of that, I'm using this approach, comma separating the columns:

    <addPrimaryKey tableName="test" columnNames="value0,value1"/>

Tested on MySQL 5.7 with liquibase 3.5.5

Upvotes: 2

Craig Ringer
Craig Ringer

Reputation: 324445

I'd be amazed if:

<createIndex indexName="idx_value"
             tableName="test">
    <column name="value" type="varchar(255)"/>
    <column name="othercolumn" type="varchar(255)"/>
</createIndex>

didn't work...

Upvotes: 24

Related Questions