Created
February 9, 2012 00:52
-
-
Save mahemoff/1776043 to your computer and use it in GitHub Desktop.
Rails mass migration to add indexes
This file contains hidden or 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
| 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