PGConf West 2007 video - Best Practices with Rails and PostgreSQL
This is kind of a blast from the past - it's a talk by Bricolage lead developer David Wheeler at PostgreSQL Conference West 2007. It's mainly an introduction to Rails, but David's a real PostgreSQL guru (and had a Rails app that was bought by Twitter) and thus brings out some interesting points. Here are some highlights from an initial listen:
- Some basics on Rails competitors and philosophy. Someone in the audience mentions Grails.
- ActiveRecord validations and callbacks. A few minutes on ActionView and ActionController
- Migrations. This was prior to timestamped migrations, so he talks about numbered migrations. Discusses creating indexes, the lack of built support for views. Suggests using
ActiveRecord::Base.connection.executeto just run raw SQL as necessary. Shows an example that usesSET DEFAULT CURRENT TIMESTAMP. - Talks about the araddconstraint plugin. Probably foreigner (as mentioned on Ruby5) is the current leader for adding foreign key constraints, although I haven't used it. Looks good though.
- Demonstrates a class-level finder that uses PostgreSQL-specific SQL - specifically, the
LOWERfunction. This talk predatesnamed_scope, so, there ya go. - At around 28:00 he notes problem with using Slony and migrations - e.g., how do you get to the SQL so you can send it off to your Slony instance? In his case they just stopped using Slony and went to a warm standby, probably with WAL shipping.
- Talks about loading large data sets using
COPY. I've found that this is the right way to get lots of data in a PostgreSQL database as well. Don't waste time using models for stuff like that. - Discusses skinny controllers and fat models.
- At 32:30 talks about associations and some ActiveRecord conventions.
has_many :throughwas new stuff then, I think; he useshas_and_belongs_to_manyin the example. - At 40:00 he talks about
created_atandupdated_atand time zones. He suggests that you always stores times in UTC, which is pretty standard. I think some of the possible complexities here are now built in to Rails, but I'm not sure. - At 44:30 he talks about reopening classes. This seems to be a new topic for the audience and he gets some pushback. Someone refers to it as "Ruby's GOTO." The class he reopens is the PostgreSQLAdapter; he plugs in his own version of
quoted_date. - Around 50:00 he asks if someone could please update the PostgreSQL driver. Jeff Davis is in the audience and responds to him about the updates he's doing. Today this has all been taken care of as I noted in a previous post on Ruby PostgreSQL drivers.
It's a nice presentation in front of a small group, with a nice feel to it. The audio quality is decent, although the slides are a little hard to read. Also, thanks to David for the nice email regarding this post. Enjoy!


