From 5bd5395d31be0c778607e1702b4774b51b68b5d5 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Mon, 10 Oct 2022 15:23:33 -0700 Subject: [PATCH] chore: Add missing indexes for attachments table (#5588) - index for attachments table - index for conversations table --- app/models/attachment.rb | 5 +++++ app/models/conversation.rb | 2 ++ .../20221010212946_add_index_to_message_attachments.rb | 8 ++++++++ db/schema.rb | 6 +++++- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20221010212946_add_index_to_message_attachments.rb diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 4fa1b7e57..cb877ce8a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -14,6 +14,11 @@ # account_id :integer not null # message_id :integer not null # +# Indexes +# +# index_attachments_on_account_id (account_id) +# index_attachments_on_message_id (message_id) +# class Attachment < ApplicationRecord include Rails.application.routes.url_helpers diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 3a833ef09..29eab8433 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -31,8 +31,10 @@ # index_conversations_on_account_id_and_display_id (account_id,display_id) UNIQUE # index_conversations_on_assignee_id_and_account_id (assignee_id,account_id) # index_conversations_on_campaign_id (campaign_id) +# index_conversations_on_contact_id (contact_id) # index_conversations_on_contact_inbox_id (contact_inbox_id) # index_conversations_on_first_reply_created_at (first_reply_created_at) +# index_conversations_on_inbox_id (inbox_id) # index_conversations_on_last_activity_at (last_activity_at) # index_conversations_on_status_and_account_id (status,account_id) # index_conversations_on_team_id (team_id) diff --git a/db/migrate/20221010212946_add_index_to_message_attachments.rb b/db/migrate/20221010212946_add_index_to_message_attachments.rb new file mode 100644 index 000000000..1ba2be299 --- /dev/null +++ b/db/migrate/20221010212946_add_index_to_message_attachments.rb @@ -0,0 +1,8 @@ +class AddIndexToMessageAttachments < ActiveRecord::Migration[6.1] + def change + add_index :attachments, :account_id + add_index :attachments, :message_id + add_index :conversations, :contact_id + add_index :conversations, :inbox_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 0793a6587..d719bc9f7 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: 2022_09_30_025317) do +ActiveRecord::Schema.define(version: 2022_10_10_212946) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" @@ -148,6 +148,8 @@ ActiveRecord::Schema.define(version: 2022_09_30_025317) do t.datetime "updated_at", null: false t.string "fallback_title" t.string "extension" + t.index ["account_id"], name: "index_attachments_on_account_id" + t.index ["message_id"], name: "index_attachments_on_message_id" end create_table "automation_rules", force: :cascade do |t| @@ -410,8 +412,10 @@ ActiveRecord::Schema.define(version: 2022_09_30_025317) do t.index ["account_id"], name: "index_conversations_on_account_id" t.index ["assignee_id", "account_id"], name: "index_conversations_on_assignee_id_and_account_id" t.index ["campaign_id"], name: "index_conversations_on_campaign_id" + t.index ["contact_id"], name: "index_conversations_on_contact_id" t.index ["contact_inbox_id"], name: "index_conversations_on_contact_inbox_id" t.index ["first_reply_created_at"], name: "index_conversations_on_first_reply_created_at" + t.index ["inbox_id"], name: "index_conversations_on_inbox_id" t.index ["last_activity_at"], name: "index_conversations_on_last_activity_at" t.index ["status", "account_id"], name: "index_conversations_on_status_and_account_id" t.index ["team_id"], name: "index_conversations_on_team_id"