22

What is the correct syntax to alter the table and adding multiple columns at a time using liquibase xml. The official document gives the example for adding only one column :

<changeSet author="liquibase-docs" id="addColumn-example">
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="address" type="varchar(255)"/>
    </addColumn>
</changeSet>

Now if I want to add multiple columns at a time, what is the correct syntax:

<changeSet author="liquibase-docs" id="addColumn-example">
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="job" type="varchar(255)"/>
    </addColumn>
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="designation" type="varchar(255)"/>
    </addColumn>
</changeSet>

Is it correct or

<changeSet author="liquibase-docs" id="addColumn-example">
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="job" type="varchar(255)"/>
       <column name="designation" type="varchar(255)"/>
    </addColumn>   
</changeSet>

which is correct of the two above? or something different altogether.

smart987
  • 834
  • 2
  • 14
  • 34

1 Answers1

22

Both of those examples will work.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43
  • to roll back in case add operation fails how to add roll back condition in both scenarios? – smart987 Oct 08 '15 at 18:19
  • 1
    If I remember correctly, addColumn is one of the refactorings that has a "default" rollback, which is to drop the column. If you were to use this in a situation where you wanted to preserve the data in those columns in a rollback scenario, you would need to do a custom rollback change. If in doubt, you could deploy the changelog and then use the one of the rollback commands that generates SQL (rollbackSQL, rollbackToDateSQL, or rollbackCountSQL) to preview what would happen. – SteveDonie Oct 08 '15 at 20:04