Rails 2 on Windows with Oracle: notes about getting started

February 14, 2008 Pivotal Labs

I’m planning to make this the first in a series of random small notes
about working on a Rails project in an enterprise (by which I mean large-scale, mature-company, high-demand) setting. I’m aiming for small bite-sized dispatches, not for comprehensiveness. [Edited to say: I’m now working on a Java project, so I’m not sure when I will have more to add.] Please
chime on in with additions and comments. This post focuses on our installation process. If you’ve gotten here via google, you’re going to find much more systematic guides than this, so be of good cheer!

To get going on Windows XP (which really didn’t take long after we received admin permissions for our PC) we began by installing and
configuring Cygwin. There are many good Cygwin resources, so I’ll just note that being proxied inside a firewall, we needed to set our ‘http_proxy’ environment variable to a fully qualified proxy URL (http://proxy_host:port) in order for gem to be able to pull packages down.

Also (maybe unnecessary if we got all our paths right, but I’ve had this kind of path wonkiness in Cygwin before) we needed to
alias rake, rails and gem, as in "alias gem='/cygdrive/c/ruby/bin/ruby
c:rubybingem"

We froze to Edge rails. We installed mySql first, did some scaffolding out of resources (I do love script/generate Noun) so that we had some migrations to apply. Then we made the transition to Oracle 10g local install (free).

You’ll need oci8, the Oracle connection layer. In case you miss this the way I did, there’s a binary Windows installer there for you — download it and run ruby ruby-oci8-1.0.0-mswin32.rb.

Current Rails 2 also omits the oracle connection adapter: put it in with the other connection adapters in ${RUBY_HOME}/lib/ruby/gems/1.8/gems/lib/active_record/connection_adapters/

At the moment you’ll also need to make this patch to the adapter.

Our project has a requirement for different table names than the Rails-guessable default. (The requirement is that they differ even within an Oracle view.) For this case, any database will need you to set the table name (we had trouble with set_table_name, but we were able to use def self.table_name() "my_actual_table_name" end ). With Oracle, and I would imagine with Postgres, you also need to set the sequence name:

   set_sequence_name "my_actual_table_name_seq"

or you get a “sequence does not exist” error. We flipped back to MySql at one point and didn’t get any complaints about setting sequence names in each model object, so that’s good.

If you insert data in your migrations and you have explicitly set sequence names, don’t forget that you will have to make the ID one of the inserted columns, with the value being my_actual_table_name_seq.nextval. If you aren’t monkeying with table names, ignore all of this, because the adapter will take care of sequences behind the scenes.

We tried applying a global prefix to our table names, because the prefix is the non-guessable part, but didn’t manage to make that work, presumably because we hadn’t yet figured out the sequence naming issue.

We’ve done a quick experiment with creating an updatable view, to make sure we can make that work with Rails (since the database schema is already specified and is not very Rails-friendly, we’ll mask that with views), and it just worked. The sequence gets called appropriately by the adapter for the ID. (I initially had some doubt about this, but it was just because I messed up the first version of my view by leaving out the ID field.)

Dropping the database from rake doesn’t seem to work. More importantly, we have a still-unsolved issue with not being able to reliably run “rake test” — the migration process breaks sporadically. (Individual tests run outside of rake from the command line are fine.) Our current fix is that we put the following test suite in test/test_suite.rb

       require 'test/unit'

       Dir.chdir("test")
       @@test_files = Dir.glob("**/*_test.rb")
       Dir.chdir("..")
       @@test_files.each {|x| require "test/" + x unless x.include?("selenium")}

and we’re running it from IntelliJ.

That’s probably more than enough for today. I’m on vacation for a couple of weeks. So if you share your own Oracle/Rails tips while I’m gone, I won’t be able to thank you till March… but don’t let that discourage you!

About the Author

Biography

Previous
Removing Old Ruby Source Installation After a Leopard Upgrade
Removing Old Ruby Source Installation After a Leopard Upgrade

I just upgraded to Leopard on my Mac. Previously, on Tiger, I had installed Ruby from source, in the de...

Next
Java Stink
Java Stink

After about two years in which the only Java I wrote had a "Script" after it, I've recently started working...

×

Subscribe to our Newsletter

!
Thank you!
Error - something went wrong!