docbrown/db/migrate/20210423162805_remove_indexes_from_comments.rb
Alex 1b6f753f73
Performance improvements to comments search (#13489)
* Explicitly pluck user_id from comments table

* Change comment query

* Remove indexes and add partial indexes

* Update schema
2021-04-23 13:21:30 -04:00

15 lines
873 B
Ruby

class RemoveIndexesFromComments < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
remove_index :comments, column: :commentable_type, algorithm: :concurrently if index_exists?(:comments, :commentable_type)
remove_index :comments, column: :deleted, algorithm: :concurrently if index_exists?(:comments, :deleted)
remove_index :comments, column: :hidden_by_commentable_user, algorithm: :concurrently if index_exists?(:comments, :hidden_by_commentable_user)
end
def down
add_index :comments, :commentable_type, algorithm: :concurrently unless index_exists?(:comments, :commentable_type)
add_index :comments, :deleted, algorithm: :concurrently unless index_exists?(:comments, :deleted)
add_index :comments, :hidden_by_commentable_user, algorithm: :concurrently unless index_exists?(:comments, :hidden_by_commentable_user)
end
end