Sometimes you can be seduced by shiny things. I was very seduced by Ruby and Rails (well ActiveRecord really). The premise is so simple, the reailty matches the premise for so long… It’s the development equivalent of finding out Santa Claus doesn’t exist when it becomes hard work. So what happened? Well to begin with no one knew about the Oracle license situation…we wanted to be the quick result people so we started on Postgresql. Coming to our senses we briefly spiked Oracle and found that all was good with migrations and basic data. Excellent, lets pack Oracle in a box untill much further down the line I thought.
Twelve weeks later and the model has grown from about eight objects to twenty. OK, no biggie there. So then I started looking in the code…ah, there’s a lot of erm, SQL in there isn’t there? OK, no biggie Oracle and Postgres aren’t worlds apart as dialects of SQL. Well maybe not but the differences are important. A classic example is how many arguments can you put in a where clause? Answer:
Postgres: As many as you’d like (we passed 10000+ in some queries)
Oracle: 1000
Bobbins! OK, we were being lazy with our use of ActiveRecord, so lets refactor the SQL queries (oh and Oracle? Thanks for that ROWNUM implementation, there is nothing as straightforward as wrapping one select in another). Indexes, on Oracle you’re talking about a thirty character limit, on Postgres there appears to be a limit greater than 256 characters. Migrations now need custom names, harumph!
Then there’s the drivers. In postgres land there’s a pure ruby driver called postgres-pr, which turns out to be pretty nifty, installs everywhere, never chucked an error. Mind you it was slow enough that I wouldn’t use it to run production. In oracle land theres ruby-oci8, which is a wrapper around the OCI libs. The biggest thing here is that the ruby-oci8 lib can deadlock ruby. Now I’m not certain because our environments are a lovely mix of Solaris and Oracle releases and patch levels but I think what happens is that if you use DB backed sessions then the OCI driver tries to create two sessions with the DB and gets in a knot with rails. After two weeks of battling the forces of evil we went to file backed sessions and the problem disappeared. I do see that the ruby-oci project has a version two in the offing, lets hope that sorts out some of the nastiness there. I’ve also noticed that query 1 is mighty expensive, it’s probably a connection setup thing but lordy it’s annoying when you have to stop your dev server every two minutes to hack a model object fix.
This post has lain dormant for a couple of months while I stewed on it and thought about whether or not I should release it, then today happened… We’ve just started a Rails 2 project using Oracle and the first thing we did was install the activerecord oracle adapter (which is now split from core rails), bug #1 was migrations (see update). Migrations for Pete’s sake! So I dusted this post off and if it generates some comments I’m thinking about starting off some sort of Oracle-Rails survivors group.
Update:
The migrations bug can be found on this thread.