Created
May 7, 2013 01:41
-
-
Save marshallshen/5529692 to your computer and use it in GitHub Desktop.
Add index on composite keys using Rails migration
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
def change | |
create_table :users do |t| | |
t.references :account #account_id | |
t.references :profile #profile_id | |
#... | |
end | |
add_index :accounts, [:account_id, :token], :unique => true, :name => 'by_account_token' | |
add_index :accounts, :profile_id, :unique => true, :name => 'by_profile' | |
add_index :accounts, [:account_id, :display_name], :name => 'by_account_profile' | |
#... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment