-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #779 from arpitchauhan/bugfix/check-if-indexes-exist
Guard against indexes already existing
- Loading branch information
Showing
1 changed file
with
12 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
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 |