Search code examples
javasql-serverliquibasevarcharclob

CLOB type in liquibase turns to VARCHAR in SQL Server


I have the following entry in my liquibase xml:

<changeSet author="lars" id="1">
    <createTable tableName="STATUS">
        <column autoIncrement="true" name="AUTOID" type="BIGINT">
            <constraints primaryKey="true" primaryKeyName="PK_STATUS"/>
        </column>
        ...
        <column name="DATA" type="CLOB(1048576)">
            <constraints nullable="false"/>
        </column>
        <column name="VERSION" type="BIGINT">
            <constraints nullable="false"/>
        </column>
     </createTable>
</changeSet>

But when I use liquibase to run this on an MS SQL Server Standard Edition, v12, I see that the DATA column has been created as type VARCHAR.

I use liquibase maven plugin v3.2.0

The driver I use is com.microsoft.sqlserver.jdbc.SQLServerDriver, sqljdbc42.jar, i.e. version 4.2.

Anyone has any idea why this happens?


Solution

  • Check out the ClobType.java class.

    In the method toDatabaseDataType it has an else if section for the MSSQLDatabase type:

    else if (database instanceof MSSQLDatabase) {
        ...
    

    I don't know anything about MS SQL but it seems to me that liquibase (among other things) checks the version number of the MS SQL db and returns a different type depending on the db version. Maybe this is better suited on a MS SQL db and for convenience liquibase translated it directly?