summaryrefslogtreecommitdiffstats
path: root/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb
blob: 050ca7f43196ecb3c44a417c34f32d05c4fe74d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class RemoveDuplicatedIndexOnAllTables < ActiveRecord::Migration
    def self.up
        ActiveRecord::Base.connection.tables.each do |t|
            if ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id")
                remove_index t.to_s, :id
            end
        end
    end

    def self.down
        ActiveRecord::Base.connection.tables.each do |t|
            unless ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id")
                add_index t.to_s, :id, :integer => true
            end
        end
    end
end