Sunday, December 9, 2007

PostgreSQL

RoR is amazing! I love how everything is so encapsulated! After doing another project where I switched from MySQL to PostgreSQL, I wanted to try out PostgreSQL with RoR. Usually, this means a lot of backend changes and porting SQL scripts.

However, with RoR, it requires very little changes. Firstly, your whole entire database structure is created using the migration scripts. Since the migration scripts are written in Ruby, nothing has to change about these scripts. Any database access from your application do not need to be changed since they are also in Ruby. Then you must be asking, "What needs to be changed?" Very simple, the database.yml needs to be changed. Actually, only 1 line of it. This is the configuration file that RoR uses to access the database. Just change:

adapter: mysql

to

adapter: postgresql

That's it! Really, that's it! Well, actually, no... you need to install the Ruby gem that handles PostgreSQL. Since I'm developing on a Windows machine, I just enter:

>gem install ruby-postgres

For more information, you can visit this page:

http://wiki.rubyonrails.org/rails/pages/PostgreSQL

And truly, that's it. If you don't believe me, give it a try! Changing your database couldn't be easier!


W

No comments: