Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request mbleigh#779 from arpitchauhan/bugfix/check-if-inde…
Browse files Browse the repository at this point in the history
…xes-exist

Guard against indexes already existing
  • Loading branch information
seuros authored Aug 25, 2016
2 parents 09b3fa0 + 1e71a87 commit 3b72305
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions db/migrate/6_add_missing_indexes_on_taggings.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class AddMissingIndexesOnTaggings < ActiveRecord::Migration
def change
add_index :taggings, :tag_id
add_index :taggings, :taggable_id
add_index :taggings, :taggable_type
add_index :taggings, :tagger_id
add_index :taggings, :context
add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id
add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id
add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type
add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id
add_index :taggings, :context unless index_exists? :taggings, :context

add_index :taggings, [:tagger_id, :tagger_type]
add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
unless index_exists? :taggings, [:tagger_id, :tagger_type]
add_index :taggings, [:tagger_id, :tagger_type]
end

unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
end
end
end

0 comments on commit 3b72305

Please sign in to comment.