Skip to content

Instantly share code, notes, and snippets.

@clowder
Created August 6, 2013 10:35
Show Gist options
  • Save clowder/6163460 to your computer and use it in GitHub Desktop.
Save clowder/6163460 to your computer and use it in GitHub Desktop.
Postgres UUID primary keys for your Rails 3 apps.
class UuidPrimaryKey < ActiveRecord::Migration
def up
execute 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
create_table :your_table, :id => false do |t|
# etc...
t.timestamps
end
execute 'ALTER TABLE your_table ADD COLUMN id uuid DEFAULT uuid_generate_v4() PRIMARY KEY;'
end
def down
drop_table :your_table
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment