[deploy] Optimization: Remove unused indexes from Postgres (#8693)

This commit is contained in:
Molly Struve 2020-06-16 11:13:38 -05:00 committed by GitHub
parent 8ce292870e
commit e47037087d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View file

@ -0,0 +1,31 @@
class RemoveUnusedIndexes < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
if index_exists?(:page_views, :domain)
remove_index :page_views, column: :domain, algorithm: :concurrently
end
if index_exists?(:notifications, :notifiable_id)
remove_index :notifications, column: :notifiable_id, algorithm: :concurrently
end
if index_exists?(:users, :old_username)
remove_index :users, column: :old_username, algorithm: :concurrently
end
end
def down
if !index_exists?(:page_views, :domain)
add_index :page_views, :domain, algorithm: :concurrently
end
if !index_exists?(:notifications, :notifiable_id)
add_index :notifications, :notifiable_id, algorithm: :concurrently
end
if !index_exists?(:users, :old_username)
add_index :users, :old_username, algorithm: :concurrently
end
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: 2020_06_12_140153) do
ActiveRecord::Schema.define(version: 2020_06_15_213003) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -676,7 +676,6 @@ ActiveRecord::Schema.define(version: 2020_06_12_140153) do
t.index ["created_at"], name: "index_notifications_on_created_at"
t.index ["json_data"], name: "index_notifications_on_json_data", using: :gin
t.index ["notifiable_id", "notifiable_type", "action"], name: "index_notifications_on_notifiable_id_notifiable_type_and_action"
t.index ["notifiable_id"], name: "index_notifications_on_notifiable_id"
t.index ["notifiable_type"], name: "index_notifications_on_notifiable_type"
t.index ["notified_at"], name: "index_notifications_on_notified_at"
t.index ["organization_id", "notifiable_id", "notifiable_type", "action"], name: "index_notifications_on_org_notifiable_and_action_not_null", unique: true, where: "(action IS NOT NULL)"
@ -791,7 +790,6 @@ ActiveRecord::Schema.define(version: 2020_06_12_140153) do
t.bigint "user_id"
t.index ["article_id"], name: "index_page_views_on_article_id"
t.index ["created_at"], name: "index_page_views_on_created_at"
t.index ["domain"], name: "index_page_views_on_domain"
t.index ["user_id"], name: "index_page_views_on_user_id"
end
@ -1275,7 +1273,6 @@ ActiveRecord::Schema.define(version: 2020_06_12_140153) do
t.index ["github_username"], name: "index_users_on_github_username", unique: true
t.index ["language_settings"], name: "index_users_on_language_settings", using: :gin
t.index ["old_old_username"], name: "index_users_on_old_old_username"
t.index ["old_username"], name: "index_users_on_old_username"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["twitter_username"], name: "index_users_on_twitter_username", unique: true
t.index ["username"], name: "index_users_on_username", unique: true