Add indexes to comments (#13476)

This commit is contained in:
Alex 2021-04-22 16:37:46 -04:00 committed by GitHub
parent 3483d69667
commit de23d3ec8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,15 @@
class AddIndexesToComments < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
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
def down
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
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_04_21_190438) do
ActiveRecord::Schema.define(version: 2021_04_22_171642) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
@ -392,7 +392,10 @@ ActiveRecord::Schema.define(version: 2021_04_21_190438) do
t.index ["ancestry"], name: "index_comments_on_ancestry"
t.index ["ancestry"], name: "index_comments_on_ancestry_trgm", opclass: :gin_trgm_ops, using: :gin
t.index ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type"
t.index ["commentable_type"], name: "index_comments_on_commentable_type"
t.index ["created_at"], name: "index_comments_on_created_at"
t.index ["deleted"], name: "index_comments_on_deleted"
t.index ["hidden_by_commentable_user"], name: "index_comments_on_hidden_by_commentable_user"
t.index ["score"], name: "index_comments_on_score"
t.index ["user_id"], name: "index_comments_on_user_id"
end