Grails Data Base Migration - dbm-gorm-diff is not working - grails

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.

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
Remove dbCreate from DataSource.groovy
Initially run grails dbm-generate-gorm-changelog changelog.groovy
Sync the changelog with your db by running grails dbm-changelog-sync
Changing domain
Change domain class
Run grails dbm-gorm-diff <your-filename>.groovy --add
Run grails dbm-changelog-sync
Hope this helps

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.

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

Related

Grails Test-App Tries to Insert Updated Tables Instead of Update Them

I have been building our grails app to AWS Elastic Beanstalk through Jenkins for awhile now without issue, jumping and building between branches for years. This became an issue, though, when adding the grails test suite into the build.
I set up a test database for jenkins to use itself and let grails populate all the table data on its own, it worked for several months until recently when I decided to deploy a branch that was around 6 months old to one of our development environments. As you can guess, a branch 6 months old was missing some columns that were in more recent releases, and hence in the database, so grails deleted those columns, and tested and deployed without issue.
The problem arose when I went to deploy a more recent branch to a different environment, and grails test-app started failing due to sql errors because the app was trying to use a column that didn't exist on that table.
I dug into it further and discovered in the logs that when grails should have been trying to update the tables because they already existed and just needed a column added, it was trying to insert the tables instead. Obviously this caused issue with the tables already existing and the database not being updated.
Does anyone have any knowledge on how to force grails test-app to update the database tables instead of try to insert them? This has never happened in the use of the app, so I know this is localized to an issue with the test-suite, but the documentation on it is kind of bad, especially for grails 2.3.11 so I can't find anything.
This ended up being due to the old branch that was deployed having a different dbCreate value for the test environment, so for some reason when it made it's changes with the dbCreate property of "update" then switched back to "create-drop" it no longer could drop the tables before re-adding them.

Grails DBMigrations plugin confusion in usage

I'm looking to introduce the Grails DBMigrations plugin into an existing application.
My understanding is that after installation the first thing to do is to create the initial changelog.groovy which I've done with the command
dbm-generate-gorm-changelog changelog.groovy
This does create the file correctly, and contains all the necessary commands to recreate the database schema.
Secondly my understanding is I should then issue the command dbm-changelog-sync to indicate that the changelog script has been executed.
What should happen if I then issue the command dbm-gorm-diff ?
At this point I'm expecting to see an empty changelist... because the initial schema was created, committed and no changes have been made to any domains, however I see a bunch of entries.. for modifying column types and a few index creation entries.
Any advice appreciated, I've reached this point because I want to update the database in a production env database, and don't want to start writing manual tests and SQL in bootstrap to update the DB as this will surely lead ultimately to a maintenance migraine. Using DBMigrations appears to be the way forward but either I don't understand it, or it's buggy and don't want to risk using it.
And as others have commented in other threads, I'm restarting the grails console between issuing commands to avoid reloading problems.
Thanks
Dave,
The important thing to remember about the migrations plugin is that is output from dbm-gorm-diff is not meant to be taken as gospel. It is simply meant as a way to hopefully save you from some typing. Anything generated automatically from the plugin should be reviewed and analyzed to determine that it is what you desire.

grails dbm-gorm-diff is updating db

I'm using grails database-migration to update my production db, but it' presenting a weird behaviour. I ran dbm-gorm-diff and it seems to work fine, but for some reason my prod db is getting updated without I use 'dbm-update' or put it to be executed when the war file is deployed.
What I realised so far is that it seems that any operation made on the prod environment is some how triggering an update on the db. And I couldn't figure out what.
did you set dataSource -> dbCreate to 'any other value'?
I highly doubt that this is what's happening; that would be a very serious bug, and it would have appeared before now, unless it's a very unusual combination of settings/state/db/etc. that triggers this.
If you can isolate this to a small and repeatable example please create a bug report at https://jira.grails.org/browse/GPDATABASEMIGRATION and I'll fix it ASAP.

Grails: Unable to generate views

This is a very basic thing and I have no idea why am not able to do this. I am using Grails 2.3.5
I have a domain class com.trail.AuditTrail and I want it scaffolded views. So, here are the steps I followed:
ran grails create-controller com.trail.AuditTrail, this returned a message saying it generated:
grails-app/controller/trail/AuditTrailController
grails-app/views/auditTrail (just the folder!)
It also created AuditTrailControllerSpec.groovy.
Then I added the line static scaffold = true in the Controller.
Then ran generate-views to create the views, but nothing got created !
IMPORTANT: In fact grails says that there is no command called as generate-views. When I did grails help it didn't list generate-views. So, I thought may be 2.3.5 doesn't have the command and tried generate-all. This too failed. To my surprise, grails help didn't show up generate-all too !
Then I found this bug: https://jira.grails.org/browse/GRAILS-10530. So, I tried clean, refresh-dependencies, compile and then generate-all. But still the same problem.
I thought my local grails setup is messed up. So, asked my colleague. He too sees the same problems.
My problem is I am not able to create the default template GSPs out of the domain.
Scaffolding functionality was extracted from Grails core in 2.3, so you need to install scaffolding plugin for Grails 2.3.5 to be able to use generate-all, generate-views GANT scripts.
P.S. I suggest you to switch to Grails 2.3.6 or 2.3.7. For more details take a look at this article http://www.gopivotal.com/security/cve-2014-0053
for that right click on action then click on generate view

Grails Webflow not auto-reloading

Hey all- I'm working on some web flows for a Grails app we're building. I'm (slowly) getting the hang of the webflows themselves, but progress is severely limited due to the fact that changes to the webflow controller are not auto-reloading in Tomcat on save; basically, I need to bounce the app every time I make a change. As you can imagine, this is pretty painful. I think auto-reload was working a couple of days ago and then stopped, but I'm not sure.
Has anyone else experienced this? Any thoughts on how to make auto-reload work?
Thanks!
After much trial and error, here's what I found:
Situation: I have a controller with a single webflow. The first stage of the webflow uses a command object. (Grails 1.3.1)
1) Command and Webflow in same file; Command first: everything works, but the controller will not auto-reload on save.
2) Command and Webflow in same file; Webflow first: doesn't work- a serialization exception thrown when trying to render the page that references the command object.
3) Command and Webdlow in different files: everything works and controller auto-reloads.
For now I'll just keep everything in separate files. If anyone has insight into why this behavior is being exhibited, I'm all ears.

Resources