Created
August 6, 2013 10:35
-
-
Save clowder/6163460 to your computer and use it in GitHub Desktop.
Postgres UUID primary keys for your Rails 3 apps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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