Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created February 9, 2012 00:52
Show Gist options
  • Save mahemoff/1776043 to your computer and use it in GitHub Desktop.
Save mahemoff/1776043 to your computer and use it in GitHub Desktop.
Rails mass migration to add indexes
class AddIndexes < ActiveRecord::Migration
INDEXES = {
:blogs => %w/title author_id/,
:comments => %w/blog_id subject poster_id/,
:events => %w/name place when/
}
def up
INDEXES.each { |table, cols |
cols.each { |col| add_index table, col }
}
end
def down
INDEXES.each { |table, cols |
cols.each { |col| remove_index table, col }
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment