grails-database-migration icon indicating copy to clipboard operation
grails-database-migration copied to clipboard

Changing data types is ignored by dbm-gorm-diff

Open mr-wunderlich opened this issue 9 years ago • 1 comments

I have a Domain class Example:

class Example {

    String thisIsText
    String thisIsAString

    static constraints = {
    }

    static mapping = {
        thisIsText type: 'text'
    }
}

and create the initial migration. That results in:

databaseChangeLog = {

    changeSet(author: "alexanderfranke (generated)", id: "1465390511706-1") {
        createTable(tableName: "example") {
            column(autoIncrement: "true", name: "id", type: "BIGINT") {
                constraints(primaryKey: "true", primaryKeyName: "examplePK")
            }

            column(name: "version", type: "BIGINT") {
                constraints(nullable: "false")
            }

            column(name: "this_isastring", type: "VARCHAR(255)") {
                constraints(nullable: "false")
            }

            column(name: "this_is_text", type: "CLOB") {
                constraints(nullable: "false")
            }
        }
    }
}

I now change the class by adding a further member variable and adding a further line to the mapping resulting in the following:

class Example {

    String thisIsText
    String thisIsAString
    Integer aNumber

    static constraints = {
    }

    static mapping = {
        thisIsText type: 'text'
        thisIsAString type: 'text'
    }
}

Creating a migration now will completely ignore thisIsAString:

databaseChangeLog = {

    changeSet(author: "alexanderfranke (generated)", id: "1465390799555-1") {
        addColumn(tableName: "example") {
            column(name: "a_number", type: "integer") {
                constraints(nullable: "false")
            }
        }
    }
}

Is that the expected behavior? I would have expected that it will alter the column from VARCHAR(255) to CLOB. After some further testing it also seems, that no migration is created when I change the type of thisIsAString to Integer.

The behavior was observed with POSTGRESQL as well as H2.

You can find the example at https://github.com/alexanderfranke/migrationTest

Thanks, Alex

mr-wunderlich avatar Jun 08 '16 13:06 mr-wunderlich

The issue exists in liquibase-hibernate: https://github.com/liquibase/liquibase-hibernate/issues/48

jameskleeh avatar Jul 18 '16 15:07 jameskleeh