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.
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)."
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?
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.
© 2022 - 2024 — McMap. All rights reserved.