Rails Plugin that gently allows you to use UUIDs as the primary key.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/GroupSmarts
tasks
test
CHANGELOG.txt
LICENSE
README
Rakefile
init.rb
install.rb
uninstall.rb

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