I’ve been going through some of the [http://www.ruby-lang.org/en/ ruby]/[http://api.rubyonrails.com/ ruby on rails] [http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html tutorials] and have to say it’s very interesting how easily they convert over to [http://www.postgresql.org postgresql]. In fact there are virtually no code changes neccessary (a far cry from your [http://www.awtrey.com/tutorials/dbeweb/ average php tutorial]); in each case so far I pretty much just redefined my database.yml file to point to postgresql and then went about my business. When the tutorials hit you with some oddball mysql schema:
CREATE TABLE `categories` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`category` varchar(20) NOT NULL default '',
`created_on` timestamp(14) NOT NULL,
`updated_on` timestamp(14) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `category_key` (`category`)
) TYPE=[http://sql-info.de/mysql/gotchas.html MyISAM] COMMENT='List of categories';
you just write it up in the proper postgresql syntax and you’re good to go:
CREATE TABLE categories (
id serial PRIMARY KEY,
category varchar(20) DEFAULT '' UNIQUE NOT NULL,
created_on timestamptz DEFAULT now() NOT NULL,
updated_on timestamptz DEFAULT now() NOT NULL
);
You can do these simple schemas in your head, and the supplied ruby code just works, making the tutorials pretty easy to go through. Plus the “models” files still make sense since they force the application to adhere to constraints you’ve laid out in your database. For those postgresql users who want to give it a try, here is the
full sql schema, “converted” to postgresql for the [http://rails.homelinux.org/ Four Days on Rails] tutorial. I did this on-the-fly, but it should work fine in case you get stuck.