Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 975
Hugo Avatar asked Jun 02 '11 17:06

Hugo


2 Answers

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.

like image 166
Burt Beckwith Avatar answered Sep 29 '22 21:09

Burt Beckwith


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)")
  }
}
like image 20
confile Avatar answered Sep 29 '22 21:09

confile