Skip to content

Instantly share code, notes, and snippets.

@marshallshen
Created May 7, 2013 01:41
Show Gist options
  • Save marshallshen/5529692 to your computer and use it in GitHub Desktop.
Save marshallshen/5529692 to your computer and use it in GitHub Desktop.
Add index on composite keys using Rails migration
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