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
- Drops and re-creates the database when Grails starts, and drops the schema at the end of a clean shutdown.
create
- Drops and re-creates the database when Grails starts, but doesn't drop the schema at the end of a clean shutdown.
update
- Creates the database if it doesn't exist, and modifies it if it does exist. The modifications are rather basic though, and generally only include adding missing columns and tables. Will not drop or modify anything.
validate
- Makes no changes to your database. Compares the configuration with the existing database schema and reports warnings.
- any other value - does nothing. Don't specify any value if you want to manage databases yourself or by using a 3rd-party tool.
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