Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cch1/uuid_primary_key
Rails Plugin that gently allows you to use UUIDs as the primary key.
https://github.com/cch1/uuid_primary_key
Last synced: 25 days ago
JSON representation
Rails Plugin that gently allows you to use UUIDs as the primary key.
- Host: GitHub
- URL: https://github.com/cch1/uuid_primary_key
- Owner: cch1
- License: mit
- Created: 2009-02-25T14:22:49.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2009-05-29T21:04:01.000Z (over 15 years ago)
- Last Synced: 2024-04-16T17:31:08.981Z (8 months ago)
- Language: Ruby
- Homepage:
- Size: 95.7 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: CHANGELOG.txt
- License: LICENSE
Awesome Lists containing this project
README
UUIDPrimaryKey
==============Copyright 2006-2007, Chris Hapgood
MIT License
Derived from the works of several others, including Demetrio Nunes, Paul Dix and Lee Jensen.Requirements: UUIDTools GEM (gem install uuidtools)
In any model class requiring a UUID PK, invoke UUIDPrimaryKey, optionally with
the name of the PK column in your database. Example:class Person < ActiveRecord::Base
UUIDPrimaryKey
end
class Place < ActiveRecord::Base
UUIDPrimaryKey :column => 'uuid'
end
Hints:
1. To override the value of the PK from the application, define an
initialize method in your model like this:
class Person < ActiveRecord::Base
UUIDPrimaryKey :column => 'uuid'
def initialize(params = nil)
super
self.id = params[:uuid] unless params[:uuid].nil?
end
end
2. To define a reasonable colum using migrations, try this:
class AddPeople < ActiveRecord::Migration
def self.up
create_table :people, :id => false do |t|
t.column :uuid, :string, :limit => 36
t.column :firstnames, :string, :limit => 55
t.column :lastname, :string, :limit => 35
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
end
execute("ALTER TABLE people ADD PRIMARY KEY(uuid)")
end
def self.down
drop_table :people
end
end