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

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