diff --git a/db/migrate/20210422171642_add_indexes_to_comments.rb b/db/migrate/20210422171642_add_indexes_to_comments.rb new file mode 100644 index 000000000..66050f125 --- /dev/null +++ b/db/migrate/20210422171642_add_indexes_to_comments.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index d1b7e8c57..f4bbd33af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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