addNotNullConstraint and Numeric Values

I’m assuming there is probably a simple answer here and I’m just missing it.


We have a number of columns (INT datatype) we want to assign default values to when using the addNotNullConstraint.


For Example from our Changelog:

  1. I'm also using Liquibase 2.0.2.

I think it looks like a bug. Since everything from the changelog is parsed as a string, it is difficult to automatically determine what should be escaped with quotes and which does not and trying to do it automatically runs into problems. WIth 2.0 we added valueNumeric etc. versions of “value” attributes, but didn’t add a defaultNullValueNumeric apparently.


I created http://liquibase.jira.com/browse/CORE-1064 to track the issue


Nathan

Thanks Nathan.


For now I guess we will use a custom SQL tag to get around this.

We ran into this also.  We made a temporary patch to the code, by modifying AddNotNullConstraintChange.java, method generateStatements().

 

Original code (2.0.2 version):

 

        if (defaultNullValue != null) {
            String defaultValue = TypeConverterFactory.getInstance()
                    .findTypeConverter(database).getDataType(
                            getDefaultNullValue()).convertObjectToString(
                            getDefaultNullValue(), database);
           
            statements.add(new UpdateStatement(schemaName, getTableName())
                    .addNewColumnValue(getColumnName(), defaultValue)
                    .setWhereClause(getColumnName() + " IS NULL"));
        }

We commended out the first statement, and changed ‘defaultValue’ to ‘defaultNullValue’ in the second statement, like this:

 

        if (defaultNullValue != null) {
//            String defaultValue = TypeConverterFactory.getInstance()
//                    .findTypeConverter(database).getDataType(
//                            getDefaultNullValue()).convertObjectToString(
//                            getDefaultNullValue(), database);

            statements.add(new UpdateStatement(schemaName, getTableName())
                    .addNewColumnValue(getColumnName(), defaultNullValue)
                    .setWhereClause(getColumnName() + " IS NULL"));
        }

and rebuilt.  It’s not perfect, but it’s a whole lot better.

 

Bob Sandiford

SirsiDynix