How do I modify a column using Grails' databas

2020-07-14 14:13发布

Can you give me an example of a groovy changeset using the modifyDataType method?

I tried this:

databaseChangeLog = {
  changeSet(author: "user", id: "5-1") {
        modifyDataType(tableName: "test", columnName: "description4", newDataType: "int(11)")
    }
}

But modifyDataType is not recognized. I also tried modifyColumn, but I get the same result.

The underlying question is: What kind of tags does the dsl support, and how are they used?

2条回答
贼婆χ
2楼-- · 2020-07-14 15:06

It will work like this:

databaseChangeLog = {

  changeSet(author: "test (generated)", id: "1422541392309-2") {
    comment { 'Rename tabTitle to tabName' }
    renameColumn(tableName: "user", oldColumnName: "tab_title", newColumnName: "tab_name", columnDataType: "varchar(255)")
  }
}
查看更多
家丑人穷心不美
3楼-- · 2020-07-14 15:12

All Liquibase refactorings should work - the Groovy DSL mirrors the Liquibase XML. I didn't have a test for modifyDataType but added it to my test script and it worked fine - see https://github.com/grails-plugins/grails-database-migration/blob/master/testapp/price.changelog.groovy

It'd be useful to figure out what's wrong if you could show some information about how it fails.

查看更多
登录 后发表回答