views:

273

answers:

2

Hi, I'd like to know your approach/experiences when it's time to initially populate the Grails DB that will hold your app data. Assuming you have CSVs with data, is is "safer" to create a script (with whatever tool fits you) that:

1.-Generates the Bootstrap commands with the domain classes, run it in test or dev environment and then use the native db commands to export it to prod?

2.-Create the DB's insert script assuming GORM's version = 0 and incrementing manually the soon-to-be autogenerated IDs ?

My fear is that the second approach may lead to inconsistencies for hibernate will have the responsability for the IDs generation and there may be something else I'm missing.

Thanks in advance.

+2  A: 

Take a look at this link. This allows you to run groovy scripts in the normal grails context giving you access to all grails features including GORM. I'm currently importing data from a legacy database and have found that writing a Groovy script using the Groovy SQL interface to pull out the data then putting that data in domain objects appears to be the easiest thing to do. Once you have the data imported you just use the commands specific to your database system to move that data to the production database.

Update:

Apparently the updated entry referenced from the blog entry I link to no longer exists. I was able to get this working using code at the following link which is also referenced in the comments. http://pastie.org/180868

Jared
Now, that's an elegant solution, I'll certainly try it out. ThanksBTW, the update link at the top says it's been deleted.
xain
Thanks for pointing that out. Updated answer with a link to the code and a notice that part of it was deleted.
Jared
Sorry about the broken link. I fixed it on the original post. I've also commented on that new post about a bitbucket repo that I have that has a sample updated gant script that works in grails 1.2.Blog post:http://naleid.com/blog/2008/03/31/using-gant-to-execute-a-groovy-script-within-the-grails-context-updated/#comment-2379… bitbucket repo: http://bitbucket.org/tednaleid/grails-run-script/… updated script: http://bitbucket.org/tednaleid/grails-run-script/src/tip/scripts/RunScript.groovy
Ted Naleid
A: 

Finally it seems that the simplest solution is to consider that GORM as of the current release (1.2) uses a single sequence for all auto-generated ids. So considering this when creating whatever scripts you need (in the language of your preference) should suffice. I understand it's planned for 1.3 release that every table has its own sequence.

xain