Here is how I solved this problem:
1) In my migration, I allowed the switch to id and id_sequence auto-generation and added a dummy uuid column (called guid here). It was simply the easiest way to go on a development path. So for
class Thing < ActiveRecord::Base attr_accessible :name, :description, :guid end
I use migration
class CreateThings < ActiveRecord::Migration def change create_table :things do |t| t.string :name t.string :description t.uuid :guid t.timestamps end end end
2) After migration, I can run the following through sql client
ALTER TABLE things DROP CONSTRAINT things_pkey; ALTER TABLE things ADD PRIMARY KEY (guid); ALTER TABLE things DROP COLUMN id; ALTER TABLE things RENAME COLUMN guid TO id;
3) I use two gems to help with this
gem 'uuidtools' gem 'postgres_ext'
It is clear that my solution contradicts the Postgres database ... but I am posting it because it seems like one of your problems, namely, how do you use Rails to keep db at arm's length? Anyway, UUIDtools db is agnostic.
4) In my thing class I use this
class Thing < ActiveRecord::Base include Extensions::UUID
where UUID is just such a module
module Extensions module UUID extend ActiveSupport::Concern included do
By the way, I found the latter in this meaning:
https://gist.github.com/rmoriz/937739
But my decision is a little different.