How do I modify a column using Grails' database migration plugin's Groovy DSL?
Asked Answered
V

2

6

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?

Vulcanize answered 2/6, 2011 at 17:43 Comment(4)
Since the plugin is still under development (currently version 0.2.1), the documentation probably isn't as complete as it will be once the plugin reaches v1.0. I would have thought it would have supported any liquibase refactoring, but given your experience, apparently not? You can always try opening a JIRA issue to see if it can get added to the documentation.Vig
Also, FWIW, changing the name of a domain property and running dbm-gorm-diff file.groovy creates changesets with dropColumn and addColumn instead of using modify. Perhaps column renaming/modifying is on the roadmap. You can probably write your own custom changeset to migrate the data in the short term.Vig
Although the plugin is only at v0.2.1 it's very stable and is effectively a 1.0 release candidate. There are a couple of open issues I'd like to fix before an official 1.0 and of course it needs more documentation, but otherwise it's basically feature-complete.Threnode
@Burt - Agreed that it's stable (I didn't really intend to imply that it wasn't). I've been using it for some time now and have been very happy with it. Thanks for your development on it.Vig
T
10

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.

Threnode answered 2/6, 2011 at 23:23 Comment(1)
Master is now the Grails 3 plugin, and apparently the test app was moved (I didn't work on the Grails 3 update). But the older plugin is in the "1.x" branch, and the referenced file is hereThrenode
A
3

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)")
  }
}
Ageless answered 29/1, 2015 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.