Skip to content

Commit

Permalink
Merge pull request #779 from arpitchauhan/bugfix/check-if-indexes-exist
Browse files Browse the repository at this point in the history
Guard against indexes already existing
  • Loading branch information
seuros authored Aug 25, 2016
2 parents 8fedee2 + 59c6a0d commit 6c7ee7f
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 6c7ee7f

Please sign in to comment.