Multiple Databases on Rails

Pebbles or Stones

I have been loving work recently.

A fellow geek and I have embarked on a voyage splicing a new technology into a legacy system and it's mosaic or underlying programs. Our architecture is a little funny, in the strange way, not the humorous way. Therefore, I've been presented with a never ending set of hurdles in making rails do what I need it to do.

Which is just the way I like it.

The first order of business was to get rails to talk to several different dataservers and to connect to different databases within each one. It would appear that the magic to make it all happen is to create your own base record that will connect to different databases. To show how easy it is:

# cat lib/different_database_base.rb
class DifferentDatabaseBase < ActiveRecord::Base
   establish_connection (:host=>"some_other_server",
                         :database=>"another_database",
                         :username=>"jsmith",
                         :password="letmein")
end

# cat app/model/some_class.rb
class SomeClass < DifferentDatabaseBase
end

That's all you need. Now in your controllers and views, any SomeClass objects will be retrieved through the connection to another_database. We didn't just come to this conclusion, there was a lot of bad before it got this good.

And now, I'm a believer.

Comments

Canada On Rails Slides

Slide 11

I've posted a set images to Flickr from my recent trip to see Canada on Rails. I'm not sure if the slides will be much use to those who were not at the conference, but they sure work as a great reminder to me.

Comments

Retooling Devauld.ca

Between the Clouds

As I mentioned previously, I've been tinkering under the hood of my Blog. Odds are you haven't seen that post, or this one, as I haven't updated the DNS entries that will have http://devauld.ca point to this shiney new site. I'm holding out on a couple people who I manage their mail for, so that I won't be putting them out into the cold.

First and foremost, this page is now powered by Typo instead of the homebrewed php, I had previously. I no longer host my own photography, because Flickr does a much nicer job of it. If you want to look at my photos, you can click on the snazzy little badge to the left. I love Flickr's interface so much that I modified the default Typo so that it would do a flickerish collection of my Tags, scaling the ones I post into often larger, and the ones that don't get a whole lot of love, smaller. There is also a neat live search (top of the nav bar), so you can search through the comments and posts for some words, and it's all rolled up with AJAX so you don't even have to reload the page. The comment engine has been changed so you don't need to add an e-mail address or website; simply because nobody did anyway.

You may have noticed that I love the colour green, and I stuck with a green based theme. Typo's themes are really easy to manage, although the CSS differences between IE and Firefox did bite me a couple times. The modifications to Typo were really easy too, now that I have a better understanding of how Ruby on Rails works.

Now it is time for the bad news. I started porting over all of the old content, and I realized it was going to be a swack load of work. Since the pictures are embedded in my posts, and they are now on Flickr, I would have had to look each one of the pictures for the 130 some odd posts I have photos attached to and change them. On top of that, the insertion into the new database, mangled the id's so the comments were appearing on the wrong posts. In the end, I just ended up nuking everything that was causing a problem. I'm not interesting enough for people to go that far back into my history, so I didn't think I was losing anything.

Comments

Railin’

Cramped?

I just got back from the Canada on Rails conference, and I was quite impressed. The whole thing could have been a bit more condensed, with two streams over a single day, but in the end, I learned a great deal.

I was so keen to try all the new stuff out, I managed to hijack Jerry's laptop for a few moments on the flight home to poke around a bit, to finish what I learned.

On the Thursday night of the conference a great deal of the attendees went out for Churrascaria which is always a meat lover's good time. You could tell the geek factor was very high, as most of the conversation revolved around technologies, techniques, working problems and a plethora of other geeky news.

My problem is now: I'm armed with this great view of the world, and how software should be written, but I have to go back to the enterprise where it's all about the bottom line. I'm going to fling myself against the wall until I can no longer take it, but hopefully by then we'll have a little Rails in our system.

Comments