From 9ddf4c205ca1bc78ae02730a1c19cc6d15f9b687 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Tue, 23 Aug 2022 07:35:30 -0600 Subject: [PATCH] chore: Add index on conversations.uuid (#5179) - We search for conversations by this attribute (e.g. in ReplyMailbox and CsatSurveyController) so it seems like we should have an index on it. --- app/models/conversation.rb | 2 ++ .../20220802193353_add_conversation_uuid_unique_index.rb | 5 +++++ db/schema.rb | 1 + 3 files changed, 8 insertions(+) create mode 100644 db/migrate/20220802193353_add_conversation_uuid_unique_index.rb diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 8e6d61660..3a833ef09 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -36,6 +36,7 @@ # 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) +# index_conversations_on_uuid (uuid) UNIQUE # class Conversation < ApplicationRecord @@ -51,6 +52,7 @@ class Conversation < ApplicationRecord before_validation :validate_additional_attributes validates :additional_attributes, jsonb_attributes_length: true validates :custom_attributes, jsonb_attributes_length: true + validates :uuid, uniqueness: true validate :validate_referer_url enum status: { open: 0, resolved: 1, pending: 2, snoozed: 3 } diff --git a/db/migrate/20220802193353_add_conversation_uuid_unique_index.rb b/db/migrate/20220802193353_add_conversation_uuid_unique_index.rb new file mode 100644 index 000000000..79ca8e626 --- /dev/null +++ b/db/migrate/20220802193353_add_conversation_uuid_unique_index.rb @@ -0,0 +1,5 @@ +class AddConversationUuidUniqueIndex < ActiveRecord::Migration[6.1] + def change + add_index :conversations, :uuid, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 2920c3411..b928a570d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -413,6 +413,7 @@ ActiveRecord::Schema.define(version: 2022_08_09_104508) do 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" + t.index ["uuid"], name: "index_conversations_on_uuid", unique: true end create_table "csat_survey_responses", force: :cascade do |t|