You know your code is successful when…

Like many Ruby and Rails users, I rely on an open source software named Capistrano to deploy my apps to the web. I did a quick check today to see if I had the latest version of the Capistrano gem, and was shocked and delighted to see a ton of results over and above the core gem I’m using:

$ gem list -r capistrano

capistrano (2.5.19 ruby)
capistrano-boss (0.0.1 ruby)
capistrano-campfire (0.1.1 ruby)
capistrano-cm (0.0.3 ruby)
... [many, many more] ...
capistrano_s3 (0.1.1 ruby)
capistrano_winrm (0.0.1 ruby)
CapistranoTrac (0.5.0 ruby)

There are 43 different results, 42 of which are based on Jamis Buck’s Capistrano. That’s 42 different projects, all based off this single seed.

That’s. Just. Awesome.

Judging solely by the titles I’d guess many of these gems are just small 10- or 20-liners that extend the core Capistrano gem in some narrow way. That’s even more impressive, in my mind. Building something that extensible is hard.

I love “people use and improve stuff I’ve built” as a measure of success.

Facebook User IDs are BigInts in PostgreSQL

We’ve recently been working on integrating 5 Blocks Out with Facebook, starting with making it easy to sign up via Facebook Connect. I stumbled across a bug related to this today that might impact other developers doing the same thing, so I figured it would be worth sharing.

When someone signs up on 5 Blocks Out using their Facebook account, we take their Facebook user ID (fb_uid) and save it in a database table so we can remember them later. We use PostgreSQL as our database.

Now, Facebook user IDs are integer values, and it turns out they can be pretty big. Bigger, in fact, than the default “integer” type which Rails migrations use when creating an integral-valued column in a PostgreSQL table. So if you follow the defaults, you will eventually crash when a user with a large fb_uid tries to sign up.

My code was doing something like this…

user = User.find_by_fb_uid(current_facebook_user.id)

… and with current_facebook_user.id too large, you get this unhappy result:

ERROR: value \"1000001234556789\" is out of range for type 
integer\n: SELECT * FROM \"users\" WHERE
(\"users\".\"fb_uid\" = E'1000001234556789') LIMIT 1

The solution is to use type :bigint when creating your database column. Or, as in our case, change your existing integer column from integer to bigint:

class RecoverFromDumbAssedProductionError < ActiveRecord::Migration  
  def self.up    
    change_column(:users, :fb_uid, :bigint)  
  end
end

Happy Facebooking.

Follow

Get every new post delivered to your Inbox.

Join 348 other followers