0

In order to change the decimal field I have in my table, I need to know how to have a DB migration code to have this change.

Currently the field is represents as (19,2) and need to changed to (19,3) with 3 floating digits after the point.

My database is MySql.

Thanks!

roeygol
  • 4,908
  • 9
  • 51
  • 88

2 Answers2

3

In documentation of LIQUIBASE, have a attr called modifyDataType.

Try this:

databaseChangeLog {
    changeSet(author: 'author', id: '1234') {
        modifyDataType(columnName: 'column', newDataType: 'DECIMAL(19,3)')
    }
}

I think this works fine.

Carleto
  • 951
  • 1
  • 9
  • 17
  • it works fine! but it changes from nullable 'false' => 'true'. I tried to add 'nullable: false' but it didn't work well. An exception was thrown. How can I fix it? – roeygol Aug 28 '14 at 14:47
  • Before you run the script run always dbm-update-sql. It show the sql generated by your script. Your table have a default value created? Try the addDefaultValue (http://www.liquibase.org/documentation/changes/add_default_value.html) to set default value. If a exception occurs or in this case a wrong default value is created, you run a rollback script. See in documentation of dbmigration on right panel ROLLBACK SCRIPTS or in section Groovy CHanges. – Carleto Aug 28 '14 at 15:02
  • Is there some simple solution for this case? some magic line? – roeygol Aug 28 '14 at 15:03
  • How and from where can I run the dbm-update-sql script ? – roeygol Aug 28 '14 at 15:08
  • Inside your project run, on terminal, dbm-update-script – Carleto Aug 28 '14 at 15:35
0

Solved by using: addNotNullConstraint -

changeSet(author: 'roeyg (generated)', id: '1409232538826-2') {
    addNotNullConstraint(columnDataType: 'DECIMAL(19,3)', columnName: 'value', tableName: 'period_value')
}
roeygol
  • 4,908
  • 9
  • 51
  • 88