Sunday, February 08, 2009

Converting a rails app to db2

DB2 has a long history, having ran on IBM mainframes, and mid-range for decades. Now it easy to move your rails app using it.


The lovely thing about the latest version 9.5 DB2 is that you can use
it for free, if your using the DB2-ExpressC version. It has most all the features you will need, and the database size is not limited. You can add support, or add-ons easily.

The issue you will have, if you have a existing rails app, is moving your data from mysql, or other rails database into db2.

The idea solution for this is a rails plugin, called YamlDb.

In Rails 2.1 its as easy as:
script/plugin install git://github.com/adamwiggins/yaml_db.git

rake db:data:dump
rake db:schema:dump

then update your database config file to point to db2:

development:
adapter: ibm_db
database: baseapp
username: gwest
password: xxxxxxxx

The rake db:create does not work in db2, so:
db2 create database baseapp

Then:
rake db:schema:load
rake db:data:load

And your ready to go.

Not that database names can only be 8 characters, and underlines and spaces may cause you problems. Otherwise, its painless.









2 comments:

Micah said...

yamldb is very cool! but beware, it falls flat once the database gets larger than your available RAM.

Antonio Cangiano said...

Great tip, Glenn. :)