Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Friday, January 9, 2009

Use ActiveRecord migration to manage database changes in Java projects

A sort of sequel to dumping schema into ruby. I am going to show how we can use ActiveRecord migration to manage our database change in Java projects.

Problem:
Automatically track which schema change has been made to a database.
Make it easy to recreate another database with the same schema.

Requirements:
bsf.jar (from jruby binary download)
jruby-complete jar
jdbc jar
activerecord gem
activerecord-jdbc-adapter gem

Resources:
http://www.ics.muni.cz/~makub/ruby/#c2

Steps:
install jruby
jruby -S gem install --no-rdoc --no-ri activerecord
jruby -S gem install --no-rdoc --no-ri activerecord-jdbc-adapter


Known issues:

The jruby-complete jar contains rubygems and you can package up the other gems (above) into the jruby-complete jar and distribute it (check it into vcs) that way.

Another way is to set GEM_PATH env variable to the location of the jruby gem directory.
e.g. /Users/andy/dev/tools/jruby/lib/ruby/gems/1.8

At the moment, you need to set GEM_PATH to be the jruby gem directory, which means each machine will require jruby to be installed plus the gems used.
It would be more ideal if we can just repackage jruby-complete jar with the additional gems to make deployment easier.


Update: Thanks to Nick's blog, you no longer have to set GEM_PATH to get the gems required included by the base application.