Search code examples
grailsdatabase-migrationchangelog

Why does changing mapping properties in domain doesn't generate new changelog lines?


class Donation {

    BigDecimal amount

    static constraints = {
        amount min: BigDecimal.ZERO
    }

    static mapping = {
    }

}

After the addition, the domain looked like below:

class Donation {

    BigDecimal amount       

    static constraints = {
        amount min: BigDecimal.ZERO
    }

    static mapping = {
        amount scale: 4
    }

}

After making the change, i ran dbm-gorm-diff in the grails console but it printed no additional changelog lines. I was wondering if making mapping change will not produce new changelog lines. But looking at the data type of "amount" in mysql database, it showed decimal(19,2). I thought making scale 4 will change the datatype to decimal(19, 4). I appreciate any help in this dilemma. Thanks!


Solution

  • While db-migration can detect changes in your domains and can generate the desired changelog to update your database schema. It is not smart enough to locate correct changes all the time. Specifically while you are renaming a table/column or changing the datatype of a column. In these kind of scenarios you need to make manula migrations.

    Make a manual changelog to update schema using db-migration:

    databaseChangeLog = {
    
        changeSet(author: "sandeep (manual)", id: "20150901124635-01") {
            modifyDataType(columnName: "amount", newDataType: "decimal(19,4)", tableName: "donation")
        }
    }
    

    So always, after generating the changelog, verify whether it contains the correct changes or not.