2

I am using Grails 2.3.5 with database migration plugin in new project for understand how it is working. But sometimes dbm-gorm-diff provide empty changelog file,even changes is there. For example,

i have the person domain class with out any properties. When initially creating change log, it will create 2 fields id and version in change log. After that, added 2fields name,age into that person class. then did dbm-update and dbm-gorm-diff that give like following.

databaseChangeLog = { }

Sometimes gives the changes. some times is not working. Please help me. Why it is working like that. Sorry for bad english.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Visme
  • 983
  • 8
  • 29
  • I am not very familiar with the database migration plugin. According to the documentation it says that you initially should run `dbm-generate-gorm-changelog` to generate the change log form your domain classes. It also says if `To create the changelog additions, you can either manually create the changes or with the dbm-gorm-diff script` – saw303 May 14 '14 at 06:23
  • Ya. Initially i run the command and got initial change log.After that modified the Domain, that will not come in new changelog and also we can create changelog manually .Can't we use dbm-gorm-diff always? In which scenarios i will use manual creation and dbm-gorm-diff. – Visme May 14 '14 at 06:32
  • Have you tried this tutorial? http://assarconsulting.blogspot.ch/2011/08/database-migration-in-grails.html – saw303 May 14 '14 at 07:06
  • Are you using the Grails shell or are you executing each dbm-* command individually, loading the Grails environment each time with each command call? – David Vezzani Jun 30 '14 at 21:23

3 Answers3

5

Using the following tutorial works for me. Make sure you remove dbCreate from your DataSource.groovy. According to the tutorial the workflow is as follows:

Setup

  1. Remove dbCreate from DataSource.groovy
  2. Initially run grails dbm-generate-gorm-changelog changelog.groovy
  3. Sync the changelog with your db by running grails dbm-changelog-sync

Changing domain

  1. Change domain class
  2. Run grails dbm-gorm-diff <your-filename>.groovy --add
  3. Run grails dbm-changelog-sync

Hope this helps

saw303
  • 8,051
  • 7
  • 50
  • 90
3

I have spent some time searching for the answer to this same issue.

Caveat: I am using the Grails interactive shell to issue commands, including the dbm-* commands.

By brute force alone, I have come to the conclusion that the domain classes are not reliably reloading. To get consistent results (especially with the generation of new changeLog files), any time I modify a domain class, I stop and restart the Grails interactive shell before calling dbm-gorm-diff. I've tried issuing other commands like clean, compile, package and refresh-dependencies and they just aren't working, and the -reloading flag at the start up of the Grails interactive shell doesn't seem to make any difference either.

Restarting the Grails interactive shell, however, does seem to work reliably, thought it galls me to do so :)

Those who do not use the interactive shell should not be having this problem since the domain classes are loaded with every command call.

David Vezzani
  • 1,449
  • 16
  • 24
  • I've hit this same thing. I leave the interactive shell running and use a second console tab to issue the dbm-gorm-* commands from a bare command line. – Joe Rinehart Nov 18 '14 at 10:50
2

This blog has detailed step by step explanation, specially Migrating old databases section helped us in migrating successfully.

Swapnil Sawant
  • 620
  • 8
  • 21