Grails Database-Migration Plugin - Where's my diff?
TL;DR: In your
application.yml or equivalent, set your datasource's
dbCreate to "none".
While setting up the Grails database-migration plugin in a new Grails 3.1.7 project, I encountered some strange behavior when running
dbm-gorm-diff. The command seemed to be rendering an empty changeSet, even after making multiple changes to my domain class. Searching the internet, I came across several instances of similar issues, such as this post from StackOverflow.
When watching my database during execution of
dbm-gorm-diff, I noted that the new columns were in fact showing up, leading me to suspect the problem was that the database and the domain model were in sync by the time the diff ran, resulting in my empty changeset script. I had removed the
dbCreate field from my
application.yml file, but the behavior seemed to be the same as if I had specified
Thanks to a suggestion from my OCI colleague James Kleeh, I got past this issue by setting the
dbCreate of my datasource to "none". Apparently Hibernate's default behavior is essentially the same as "update", so removing the property doesn't prevent the normal "update on start" behavior in a Grails app.