Skip to content

Instantly share code, notes, and snippets.

@roloenusa
Created July 25, 2011 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roloenusa/1103574 to your computer and use it in GitHub Desktop.
Save roloenusa/1103574 to your computer and use it in GitHub Desktop.
Ruby: Add a uniqueness key to a db.
# rails generate migration add_email_uniqueness_index
class AddEmailUniquenessIndex < ActiveRecord::Migration
def self.up
# add_index to :users. to :email, add a unique constriction.
add_index :users, :email, :unique => true
end
def self.down
remove_index :users, :email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment