Alter column length with liquibase

In Oracle a TEMP column has to be used. Below is an example;

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
 <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

<changeSet id="example_id.001" author="Jasper">
    <preConditions>
        <not>
            <columnExists tableName="USERS" columnName="ADDRESS_TEMP"/>
        </not>
    </preConditions>
    <comment>change column ADDRESS_TEMP to 20 length</comment>

    <addColumn tableName="USERS ">
        <column name="ADDRESS_TEMP" type="varchar(2000)" />
    </addColumn>

    <sql>update USERS set ADDRESS_TEMP=ADDRESS</sql>
    <dropColumn tableName="USERS" columnName="ADDRESS" />

    <addColumn tableName="USERS">
        <column name="ADDRESS" type="${numeric_20_0}" >
            <constraints nullable="false"/>
        </column>
    </addColumn>

    <sql>update USERS set ADDRESS=ADDRESS_TEMP</sql>
    <dropColumn tableName="USERS" columnName="ADDRESS_TEMP" />
</changeSet>

</databaseChangeLog>

In YAML syntax it would look like:

databaseChangeLog:
  - changeSet:
      id: sample
      author: liquibase
      changes:
        - modifyDataType:
            columnName: description
            newDataType: varchar(2000)
            tableName: account

for XML syntax see aashii's answer.


You can increase the size of your column like this:

<changeSet author="liquibase" id="sample">
    <modifyDataType
        columnName="description"
        newDataType="varchar(2000)"
        tableName="account"/>
</changeSet>

The schema defintion in your xml file doesn't allow <modifyDataType ... />.

The version of the xsd file should match the version of Liquibase you are using. The exception looks like you are using the xsd of version 1.9, see http://www.liquibase.org/documentation/xml_format.html

Tags:

Liquibase