diff options
author | Takeshi Umeda <noel.yoshiba@gmail.com> | 2020-07-08 16:23:23 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-08 09:23:23 +0200 |
commit | 606c975050e8d656ceb7130797d8adbcd12f0e49 (patch) | |
tree | 860ed858213c11ec38620a5c51d031c748754703 /db | |
parent | 258171549120142a6a7dac40f17ecc2087433f4a (diff) |
Fix RemoveDuplicatedIndexesPghero to check for the existence of the index (#14259)
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20200510181721_remove_duplicated_indexes_pghero.rb | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/db/migrate/20200510181721_remove_duplicated_indexes_pghero.rb b/db/migrate/20200510181721_remove_duplicated_indexes_pghero.rb index e2eaf46f1..1d6ba1fe9 100644 --- a/db/migrate/20200510181721_remove_duplicated_indexes_pghero.rb +++ b/db/migrate/20200510181721_remove_duplicated_indexes_pghero.rb @@ -1,12 +1,22 @@ class RemoveDuplicatedIndexesPghero < ActiveRecord::Migration[5.2] - def change - remove_index :account_conversations, name: "index_account_conversations_on_account_id", column: :account_id - remove_index :account_identity_proofs, name: "index_account_identity_proofs_on_account_id", column: :account_id - remove_index :account_pins, name: "index_account_pins_on_account_id", column: :account_id - remove_index :announcement_mutes, name: "index_announcement_mutes_on_account_id", column: :account_id - remove_index :announcement_reactions, name: "index_announcement_reactions_on_account_id", column: :account_id - remove_index :bookmarks, name: "index_bookmarks_on_account_id", column: :account_id - remove_index :markers, name: "index_markers_on_user_id", column: :user_id + def up + remove_index :account_conversations, name: :index_account_conversations_on_account_id if index_exists?(:account_conversations, :account_id, name: :index_account_conversations_on_account_id) + remove_index :account_identity_proofs, name: :index_account_identity_proofs_on_account_id if index_exists?(:account_identity_proofs, :account_id, name: :index_account_identity_proofs_on_account_id) + remove_index :account_pins, name: :index_account_pins_on_account_id if index_exists?(:account_pins, :account_id, name: :index_account_pins_on_account_id) + remove_index :announcement_mutes, name: :index_announcement_mutes_on_account_id if index_exists?(:announcement_mutes, :account_id, name: :index_announcement_mutes_on_account_id) + remove_index :announcement_reactions, name: :index_announcement_reactions_on_account_id if index_exists?(:announcement_reactions, :account_id, name: :index_announcement_reactions_on_account_id) + remove_index :bookmarks, name: :index_bookmarks_on_account_id if index_exists?(:bookmarks, :account_id, name: :index_bookmarks_on_account_id) + remove_index :markers, name: :index_markers_on_user_id if index_exists?(:markers, :user_id, name: :index_markers_on_user_id) + end + + def down + add_index :account_conversations, :account_id, name: :index_account_conversations_on_account_id unless index_exists?(:account_conversations, :account_id, name: :index_account_conversations_on_account_id) + add_index :account_identity_proofs, :account_id, name: :index_account_identity_proofs_on_account_id unless index_exists?(:account_identity_proofs, :account_id, name: :index_account_identity_proofs_on_account_id) + add_index :account_pins, :account_id, name: :index_account_pins_on_account_id unless index_exists?(:account_pins, :account_id, name: :index_account_pins_on_account_id) + add_index :announcement_mutes, :account_id, name: :index_announcement_mutes_on_account_id unless index_exists?(:announcement_mutes, :account_id, name: :index_announcement_mutes_on_account_id) + add_index :announcement_reactions, :account_id, name: :index_announcement_reactions_on_account_id unless index_exists?(:announcement_reactions, :account_id, name: :index_announcement_reactions_on_account_id) + add_index :bookmarks, :account_id, name: :index_bookmarks_on_account_id unless index_exists?(:bookmarks, :account_id, name: :index_bookmarks_on_account_id) + add_index :markers, :user_id, name: :index_markers_on_user_id unless index_exists?(:markers, :user_id, name: :index_markers_on_user_id) end end |