Created
July 25, 2011 04:47
-
-
Save roloenusa/1103574 to your computer and use it in GitHub Desktop.
Ruby: Add a uniqueness key to a db.
This file contains 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
# 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