Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice: SQL Scripting or Trusting GORM

Tags:

grails

I have always scripted all DB changes. But I'm wondering if I really need to do that with Grails applications, since GORM will make the changes automatically.

So what's the best practice for managing database changes in a Grails application?

like image 675
Brad Rhoads Avatar asked Dec 30 '22 04:12

Brad Rhoads


1 Answers

This is the pattern that I've used on several large Grails projects (and some smaller ones):

  1. In GORM we trust™ for the first stages of development (pre-production / without data)
  2. Just before releasing to the production environment start using a tool like Autobase, Liquibase, Database Migration Tasks (similar to RoR's rake), or another schema versioning utility.
  3. Maintain all database changes through the tool in an automated fashion.
  4. Test your migrations, by writing tests that exercise corner cases and data integrity to the level that you are comfortable running them on production data.

I wouldn't use straight GORM in production unless it is a smaller project that can handle a few possible speed bumps and manual interventions.

Once you start managing several environments (local development, QA/UAT, Staging, Production) you be glad that you spent the time to manage your DB changes.

Liquibase and Autobase both give you some good tools for writing many of the common refactorings, but you can always drop down into raw SQL if you want/need to.

like image 67
Colin Harrington Avatar answered Jan 05 '23 12:01

Colin Harrington