Red Squirrel Reflections
Dave Hoover explores the psychology of software development

Dave Hoover
dave.hoover@gmail.com

Categories
All [Atom]
Craftsmanship [Atom]
Dynamic [Atom]
Intersection [Atom]
Learning [Atom]
Links [Atom]
Polyglot [Atom]
Projects [Atom]
XP [Atom]
Old Blog

Obtivian Blogs

Andy Maleh
Colin Harris
Fred Polgardy
Jake Scruggs
Kevin Taylor
Leah Welty-Rieger
Ryan Platte
Todd Webb
Tyler Jennings

Archives

October 2008 (1)
September 2008 (1)
June 2008 (4)
April 2008 (3)
March 2008 (1)
February 2008 (1)
August 2007 (1)
July 2007 (1)
June 2007 (1)
May 2007 (4)
April 2007 (3)
March 2007 (5)
February 2007 (6)
January 2007 (6)
December 2006 (10)
November 2006 (5)
October 2006 (8)
September 2006 (8)
August 2006 (5)
July 2006 (12)
June 2006 (7)
May 2006 (5)
April 2006 (5)
March 2006 (4)
February 2006 (2)
January 2006 (5)
December 2005 (5)
November 2005 (3)
October 2005 (3)
September 2005 (6)
August 2005 (4)
July 2005 (7)
June 2005 (14)
May 2005 (6)
April 2005 (8)
March 2005 (9)
February 2005 (11)
January 2005 (16)
Old Archives

 

Fri, 29 Sep 2006

Rails Across 3 Oracle Databases

Over the last couple weeks at my main client, a small revolution has begun. This medium-sized Java shop is slowly, but surely adopting Ruby and Rails. It has been exciting to be a witness to the productivity gains and the willingness of people to learn something new. (Thanks in no small part to the simplicity and power of Watir.) I'll have more stories to share about this little revolution, but first I need to tell the story of a 30-minute development episode that Tyler and I just paired on.

Short version: Rails can integrate wonderfully across multiple legacy Oracle databases.

Longer version:

Over the course of my Rails development experience, I've (wrongly) assumed that trying to get Rails to do enterprise'y things is difficult. I'm not going to go into why I assumed this, but I would bet that there are others out there who have been scared into believing that they shouldn't try to swim against the Rails' convention of a single database with specific table-naming conventions.

My assumption was blown out of the water this morning when my pair and I needed to grab data from 2 other databases for a little Rails app that we created yesterday. The app was the brain-child of our client manager who needed a way to track the status of features and bug-fixes as they progressed through QA. We use XPlanner for iteration planning and iTracker for bug tracking, so she wanted to be able to refer to an XPlanner story id and/or an iTracker issue id for each QA task. We were able to deliver this to production in about an hour (thank you Capistrano) yesterday afternoon (yes, T is approaching zero).

This morning, our client said that she didn't want to see the issue and story ids, she wanted to see the name of the issue and story. For that, we needed to grab them from the XPlanner and iTracker databases. With much wringing of hands, and prepared to see our Rails productivity plummet, we Google'd around to see how to connect to multiple databases in Rails. First, we needed to configure our databases:

config/database.yml
production:
  adapter: oci
  username: foo
  password: 
  host: FOO:5353/BAR

planner:
  adapter: oci
  username: xplanner
  password: 
  host: (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=...

tracker:
  adapter: oci
  username: itracker
  password: 
  host: (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=...
Then we needed models to represent the issue and story.
app/models/story.rb
class Story < ActiveRecord::Base
end

app/models/issue.rb
class Issue < ActiveRecord::Base
end
Then we needed to create the associations between a QA task and the Issue and Story.
app/models/task.rb
class Task < ActiveRecord::Base
  belongs_to :issue
  belongs_to :story
  ...
end
Then we needed to configure Rails to use the appropriate connection and table names for Issue and Story.
config/environment.rb
Story.establish_connection "planner"
Story.set_table_name "story"

Issue.establish_connection "tracker"
Issue.set_table_name "issuebean"
And this just works:
task = Task.find(1) # from prod Oracle database
puts task.story.name # from XPlanner Oracle database
puts task.issue.description # from iTracker Oracle database

[/dynamic] permanent link


powered by blosxom