Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

liquibase: can you specify "after column" with liquibase addColumn?

Is there a way to write a liquibase addColumn changeset so it generates sql like

ALTER TABLE xxx ADD COLUMN yyy AFTER zzz;

I mean, is there a way to add an equivalent of "after column zzz" in liquibase jargon?

like image 436
PapaFreud Avatar asked Jan 17 '14 07:01

PapaFreud


2 Answers

Until this is fixed, you can use modifySql.

<changeSet id="1-1" author="david">
    <comment>Add column field to example table</comment>
    <addColumn tableName="example">
        <column name="name" type="VARCHAR(50)" defaultValue="">
            <constraints nullable="false"/>
        </column>
    </addColumn>

    <!-- Use modifySql so we can insert it in the desired position -->
    <modifySql>
        <append value=" AFTER some_column"/>
    </modifySql>
</changeSet>
like image 88
David Keen Avatar answered Sep 23 '22 03:09

David Keen


With Liquibase 3.1 there are new "afterColumn", "beforeColumn" and "position" attributes on the column tag.

The documentation at http://www.liquibase.org/documentation/column.html was just updated to include them.

like image 22
Nathan Voxland Avatar answered Sep 22 '22 03:09

Nathan Voxland