What happens when dbCreate is not specified?
Asked Answered
S

3

6

According to the official Grails documentation, it is recommended NOT to specify the dbCreate property in production. So, what happens in that case? Will Grails do anything, such as validation, when the production war file is initially loaded on the container (Tomcat, for instance)? If validation is done, what is the difference from dbCreate="validate"? Or simply nothing, leaving it up to the developer to make sure the mapping between the domain classes and the database schema is correct? Thank you in advance.

Southdown answered 15/9, 2013 at 21:56 Comment(0)
C
13

When dbCreate is not specified, is set to an empty string (dbCreate = ""), or is set to anything other than create, create-drop, update, or validate, then simply nothing happens. The database does not get created, validated, or updated.

From the doc, you can use create, create-drop, update, or validate, and "any other value - does nothing". It also says "You can also remove the dbCreate setting completely, which is recommended once your schema is relatively stable and definitely when your application and database are deployed in production. Database changes are then managed through proper migrations, either with SQL scripts or a migration tool like Liquibase (the Database Migration plugin uses Liquibase and is tightly integrated with Grails and GORM)."

Christcrossrow answered 15/9, 2013 at 22:18 Comment(2)
If you have anyone up the "food chain" who knows enough to be dangerous but not enough to understand what is happening, I would NOT recommend using "none" and use "" instead. I used "none" and one of the users saw the "WARN cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none" message then darn near had a coronary. I had to spend an hour explaining the difference between a warning and an error.Severn
Thanks, @StephenGelman. I removed the part that said "none". Hopefully people won't do that.Christcrossrow
G
3

Keeping dbCreate empty is a very bad idea: configuration is merged with that of the individual plugins and nothing good can happen if the configuration system decides you haven't set your dbCreate property and decides to use the value supplied by a random plugin. What if that plugin orders a drop-create on your multiple gigabyte (or even production) database?

Gentlemanatarms answered 1/9, 2016 at 12:36 Comment(1)
I just suffered this. I don't know why that works this way.Hurwit
I
0

Although the accepted answer is still right and the question doesn't tag a specific version, I have to point out that the grails docs has changed a bit since grails 2:

Setting the dbCreate setting to "none" is recommended once your schema is relatively stable and definitely when your application and database are deployed in production. Database changes are then managed through proper migrations, either with SQL scripts or a migration tool like Flyway or Liquibase. The Database Migration plugin uses Liquibase.

Indraft answered 27/4, 2021 at 5:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.