Search code examples
grailsgrails-ormdatabase-migration

Grails Database Migration - change domain attribute max size/length


I am having a domain model which up until today has had:

title(maxSize: 150, nullable: false, blank: false)

But now, the title max size should be changed to 256. Even if I change it and run dbm-gorm-diff, in the changeset file, I do not see anything changed related to this domain model.

Does DBM cover such migration? if so, why don't I see it? I have found this but it was terribly unhelpful ...

Thanks!


Solution

  • maxSize attribute in constrait closure - is validation rule for grails. by default String field create an column in db with type: varchar(255), as you can understand it's list of chars(i.e. String) with max length 255. If you need more char length you should change type of your field to 'longtext'(it maybe more smaller types, but I usually use it) it can contain 2147483647 chars. Next thing you should add to you changelog.groovy:

    changeSet(author: "Alexandr", id: "ID") {
            modifyDataType(tableName: "YOUR_TABLE_NAME", columnName: "title", newDataType: "longtext")
        }
    

    you just need to change id and tableName. id should be unique, table name it's tableName(not domain name) of your entity.