27 April 2013

UPD: See my second, more detailed post about the matter.

Aaron recently added uuid primary key support to Rails4 edge. To try it in your app simply create a migration like this:

create_table :users, id: false do |t|
  t.primary_key :id, :uuid
  t.string :name
  t.timestamps
end

Rails now automatically sets the default value to uuid_generate_v4() for the primary_key.

You’ll of course need to run CREATE EXTENSION "uuid-ossp"; in Postgres, either manually or with a migration via a execute statement.



blog comments powered by Disqus