Referential Integrity in Rails *Part 1*

I have started using Rails framework recently on a internal software engineering project at my workplace, prototyping an Enterprise 2.0 application that encompasses all the usual social collaborative/networking softwares that you can think of.

For the obvious reasons, it seems it will turn out a lot easier to write the software from scratch (am breaking the re-inventing the wheel commandment here) that to grab all the free open source apps and hack and integrate and put all of them into 1 place. The pain of reading PHP code is just unbearable. The thought of integrating all the databases is nightmarish. I am traditionally not a database g33k.

So once again, I turned to Ruby on Rails for a solution. Being as much a Ruby newbie as I am, I started reading tutorials online. The Ruby syntaxes are horrible, and coming from a Java background, reading the API is a pain. However, I still stick my faith in it since it is an Agile tool, and I am still obsessed with the “Build-Your-Blog-In-15-Minutes” tutorial from the site.

I finally started out like all what other engineers do, modelling the required data and defining the relationships. While it didn’t take too much effort to come out with a high level data model, it certainly has taken me half my life to define and enforce referential integrity in the database….the most CRUCIAL in my opinion. Err…did I mention it takes an external plugin just to enforce referential integrity? Oh no!!!!!!!!

I wonder how the author missed out on such an important piece of functionality in Rails. Of course, some of you will undoubtly say “Create your own database using good old SQL, you slack-jaw yockel”, but like I mentioned abovehand, I am trying to do this the AGILE way……

I am still trying hard to see how well this plugin will function. Apparently it lets you specify the integrities when you use migrate to “migrate/create/update” your database. I have to say I am pretty impress with migrate, but if the documentation about it is better, or if someone can create like a “Migrate 101″ page, it will be really awesome. Migrate looks like a generic SQL wrapper I wrote in one of my University projects before.

Needless to say, Rails is still an awesome framework for fast prototyping. My manager wanted a complete “SQL dump” on the schemas once the whole app is done. I wonder how well it will work when the schema is ported as the relationships are only defined in the applications, but not at the database level. Will see how that goes…..

Share/Save/Bookmark

Discussion Area - Leave a Comment