[deploy] Remove additional superfluous indexes (#10530)

This commit is contained in:
rhymes 2020-10-02 16:20:08 +02:00 committed by GitHub
parent e9761fde7c
commit 4e352020a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 12 deletions

View file

@ -0,0 +1,52 @@
class RemoveSuperfluousIndexesPart1 < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
# covered by index_articles_on_slug_and_user_id
if index_exists?(:articles, :slug)
remove_index :articles, column: :slug, algorithm: :concurrently
end
# covered by index_rating_votes_on_user_id_and_article_id_and_context
if index_exists?(:rating_votes, :user_id)
remove_index :rating_votes, column: :user_id, algorithm: :concurrently
end
# covered by idx_pins_on_pinnable_id_profile_id_profile_type_pinnable_type
if index_exists?(:profile_pins, :pinnable_id)
remove_index :profile_pins, column: :pinnable_id, algorithm: :concurrently
end
# covered by index_reactions_on_reactable_id_and_reactable_type
if index_exists?(:reactions, :reactable_id)
remove_index :reactions, column: :reactable_id, algorithm: :concurrently
end
# covered by index_reactions_on_user_id_reactable_id_reactable_type_category
if index_exists?(:reactions, :user_id)
remove_index :reactions, column: :user_id, algorithm: :concurrently
end
end
def down
unless index_exists?(:articles, :slug)
add_index :articles, :slug, algorithm: :concurrently
end
unless index_exists?(:rating_votes, :user_id)
add_index :rating_votes, :user_id, algorithm: :concurrently
end
unless index_exists?(:profile_pins, :pinnable_id)
add_index :profile_pins, :pinnable_id, algorithm: :concurrently
end
unless index_exists?(:reactions, :reactable_id)
add_index :reactions, :reactable_id, algorithm: :concurrently
end
unless index_exists?(:reactions, :user_id)
add_index :reactions, :user_id, algorithm: :concurrently
end
end
end

View file

@ -0,0 +1,61 @@
class RemoveSuperfluousIndexesPart2 < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
# covered by index_subscriber_id_and_email_with_user_subscription_source
if index_exists?(:user_subscriptions, :subscriber_id)
remove_index :user_subscriptions, column: :subscriber_id, algorithm: :concurrently
end
# covered by index_badge_achievements_on_badge_id_and_user_id
if index_exists?(:badge_achievements, :badge_id)
remove_index :badge_achievements, column: :badge_id, algorithm: :concurrently
end
# covered by index_badge_achievements_on_user_id_and_badge_id
if index_exists?(:badge_achievements, :user_id)
remove_index :badge_achievements, column: :user_id, algorithm: :concurrently
end
# covered by index_chat_channel_memberships_on_chat_channel_id_and_user_id
if index_exists?(:chat_channel_memberships, :chat_channel_id)
remove_index :chat_channel_memberships, column: :chat_channel_id, algorithm: :concurrently
end
# covered by index_chat_channel_memberships_on_user_id_and_chat_channel_id
if index_exists?(:chat_channel_memberships, :user_id)
remove_index :chat_channel_memberships, column: :user_id, algorithm: :concurrently
end
# covered by index_response_templates_on_user_id_and_type_of
if index_exists?(:response_templates, :user_id)
remove_index :response_templates, column: :user_id, algorithm: :concurrently
end
end
def down
unless index_exists?(:user_subscriptions, :subscriber_id)
add_index :user_subscriptions, :subscriber_id, algorithm: :concurrently
end
unless index_exists?(:badge_achievements, :badge_id)
add_index :badge_achievements, :badge_id, algorithm: :concurrently
end
unless index_exists?(:badge_achievements, :user_id)
add_index :badge_achievements, :user_id, algorithm: :concurrently
end
unless index_exists?(:chat_channel_memberships, :chat_channel_id)
add_index :chat_channel_memberships, :chat_channel_id, algorithm: :concurrently
end
unless index_exists?(:chat_channel_memberships, :user_id)
add_index :chat_channel_memberships, :user_id, algorithm: :concurrently
end
unless index_exists?(:response_templates, :user_id)
add_index :response_templates, :user_id, 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_10_01_154006) do
ActiveRecord::Schema.define(version: 2020_10_02_102303) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
@ -165,7 +165,6 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.index ["published"], name: "index_articles_on_published"
t.index ["published_at"], name: "index_articles_on_published_at"
t.index ["slug", "user_id"], name: "index_articles_on_slug_and_user_id", unique: true
t.index ["slug"], name: "index_articles_on_slug"
t.index ["user_id"], name: "index_articles_on_user_id"
end
@ -190,9 +189,7 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.datetime "updated_at", null: false
t.bigint "user_id", null: false
t.index ["badge_id", "user_id"], name: "index_badge_achievements_on_badge_id_and_user_id", unique: true
t.index ["badge_id"], name: "index_badge_achievements_on_badge_id"
t.index ["user_id", "badge_id"], name: "index_badge_achievements_on_user_id_and_badge_id"
t.index ["user_id"], name: "index_badge_achievements_on_user_id"
end
create_table "badges", force: :cascade do |t|
@ -312,9 +309,7 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.datetime "updated_at", null: false
t.bigint "user_id", null: false
t.index ["chat_channel_id", "user_id"], name: "index_chat_channel_memberships_on_chat_channel_id_and_user_id", unique: true
t.index ["chat_channel_id"], name: "index_chat_channel_memberships_on_chat_channel_id"
t.index ["user_id", "chat_channel_id"], name: "index_chat_channel_memberships_on_user_id_and_chat_channel_id"
t.index ["user_id"], name: "index_chat_channel_memberships_on_user_id"
end
create_table "chat_channels", force: :cascade do |t|
@ -968,7 +963,6 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.string "profile_type"
t.datetime "updated_at", null: false
t.index ["pinnable_id", "profile_id", "profile_type", "pinnable_type"], name: "idx_pins_on_pinnable_id_profile_id_profile_type_pinnable_type", unique: true
t.index ["pinnable_id"], name: "index_profile_pins_on_pinnable_id"
t.index ["profile_id"], name: "index_profile_pins_on_profile_id"
end
@ -990,7 +984,6 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.bigint "user_id"
t.index ["article_id"], name: "index_rating_votes_on_article_id"
t.index ["user_id", "article_id", "context"], name: "index_rating_votes_on_user_id_and_article_id_and_context", unique: true
t.index ["user_id"], name: "index_rating_votes_on_user_id"
end
create_table "reactions", force: :cascade do |t|
@ -1006,10 +999,8 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.index ["created_at"], name: "index_reactions_on_created_at"
t.index ["points"], name: "index_reactions_on_points"
t.index ["reactable_id", "reactable_type"], name: "index_reactions_on_reactable_id_and_reactable_type"
t.index ["reactable_id"], name: "index_reactions_on_reactable_id"
t.index ["reactable_type"], name: "index_reactions_on_reactable_type"
t.index ["user_id", "reactable_id", "reactable_type", "category"], name: "index_reactions_on_user_id_reactable_id_reactable_type_category", unique: true
t.index ["user_id"], name: "index_reactions_on_user_id"
end
create_table "response_templates", force: :cascade do |t|
@ -1023,7 +1014,6 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.index ["content", "user_id", "type_of", "content_type"], name: "idx_response_templates_on_content_user_id_type_of_content_type", unique: true
t.index ["type_of"], name: "index_response_templates_on_type_of"
t.index ["user_id", "type_of"], name: "index_response_templates_on_user_id_and_type_of"
t.index ["user_id"], name: "index_response_templates_on_user_id"
end
create_table "roles", force: :cascade do |t|
@ -1180,7 +1170,6 @@ ActiveRecord::Schema.define(version: 2020_10_01_154006) do
t.index ["author_id"], name: "index_user_subscriptions_on_author_id"
t.index ["subscriber_email"], name: "index_user_subscriptions_on_subscriber_email"
t.index ["subscriber_id", "subscriber_email", "user_subscription_sourceable_type", "user_subscription_sourceable_id"], name: "index_subscriber_id_and_email_with_user_subscription_source", unique: true
t.index ["subscriber_id"], name: "index_user_subscriptions_on_subscriber_id"
t.index ["user_subscription_sourceable_type", "user_subscription_sourceable_id"], name: "index_on_user_subscription_sourcebable_type_and_id"
end