The
dbCreate
property of the
DataSource
definition is important as it dictates what Grails should do at runtime with regards to automatically generating the database tables from
GORM classes. The options are:
create-drop
- Drop and re-create the database when Grails is run
create
- Create the database if it doesn't exist, but don't modify it if it does. Deletes existing data.
update
- Create the database if it doesn't exist, and modify it if it does exist
Both create-drop
and create
will destroy all existing data hence use with caution!
In
development mode
dbCreate
is by default set to "create-drop":
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
}
What this does is automatically drop and re-create the database tables on each restart of the application. Obviously this may not be what you want in production.
Although Grails does not currently support Rails-style Migrations out of the box, there are currently three plugins that provide similar capabilities to Grails: Autobase (http://wiki.github.com/RobertFischer/autobase), The LiquiBase plugin and the DbMigrate plugin both of which are available via the grails list-plugins
command