views:

40

answers:

2

Does grails have an automatic constraint update. If we change the field in domain class to be nullable by adding constraint, it is not getting reflected in database without schema export. Is it possible to do get grails do this update automatically.

+2  A: 

No, Grails/Hibernate won't automatically update your DB schema (except from simple cases like adding a new attribute), because this is no task that can be reliably automated (especially with changed data types or constraints). What would Hibernate be supposed to do with existing data, if you change the data type of a property from String to int?

So, this stuff has to be done manually. However, there is tool support for this, namely the Autobase plugin, which is based on liquibase. If you have ever developed with RoR you might be familiar with migrations - that's essentially what autobase is providing. I can definitely recommend autobase/liquibase, we are using it in all our production projects.

Daniel Rinser
A: 

The most basic thing you could do is this.

You should be maintaining a change log for your application, these DB schema changes should be recorded within this log (just a text file) as you make them. Then each release you make should have an associated SQL script (If there are DB changes), this script should handle these constraint changes (and other things...).

You must test this SQL script against your staging environment first before running it on production.

Also, you might wait to maintain a DB schema version within your DB (in a meta sort of table), Rails migrations do this.

The above is not an exhaustive howto, just general guide lines

tinny