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

default column values are incorrectly handled by diffs

Open edwardotis opened this issue 8 years ago • 6 comments

Given

class Apple{
Boolean isGood = false

    static mapping = {
        isGood defaultValue: false
    }
}

a. I have to hand correct the diff to add defaultvalueboolean:

changeSet(author: "me (generated)", id: "1486375845934-1") { addColumn(tableName: "apple") { column(name: "is_good", type: "boolean", defaultValueBoolean: false) { constraints(nullable: "false") } } }

b. After applying update, the next diff will try to remove it

    changeSet(author: "me (generated)", id: "1486614694673-15") {
        dropDefaultValue(columnDataType: "boolean", columnName: "is_good", tableName: "apple")
    }

So basically, the plugin (or underlying libraries) break default values.

http://docs.grails.org/3.1.14/ref/Database%20Mapping/column.html


runtime 'org.grails.plugins:database-migration:2.0.0 grails 3.1.14 postgres 9.6 java 8

edwardotis avatar Feb 09 '17 05:02 edwardotis

Did you specify compile 'org.liquibase:liquibase-core:3.5.3' in your build.gradle ?

jameskleeh avatar Mar 05 '17 15:03 jameskleeh

Yes, I did. compile 'org.liquibase:liquibase-core:3.5.3'

edwardotis avatar Mar 10 '17 06:03 edwardotis

FYI, I have just added the following to a domain:

valuationRate defaultValue: 100.00

And liquibase correctly detects the default, and does no longer generate a dropDefaultValue.

org.liquibase:liquibase-core:3.5.3
Grails Version: 3.2.6
Groovy Version: 2.4.7
JVM Version: 1.8.0_121
MySQL 5.7.19-1.1.1

yackx avatar Oct 11 '17 08:10 yackx

@edwardotis it's working with the latest liquibase-core version compile 'org.liquibase:liquibase-core:3.5.5'

rkrause88 avatar Mar 16 '18 05:03 rkrause88

It doesn't work with defaultValue: false

It works with with strings, numbers, and defaultValue: true

tekells-usgs avatar Apr 25 '19 20:04 tekells-usgs

It seems like defaultValue mapping doesn't work with falsy values like false and 0. I'm using compile 'org.liquibase:liquibase-core:3.10.1'

cgray9 avatar Jan 18 '21 17:01 cgray9