diff --git a/db/migrate/20260807101420_add_account_status_created_at_index_to_conversations.rb b/db/migrate/20260807101420_add_account_status_created_at_index_to_conversations.rb new file mode 100644 index 000000000..03a1e7c50 --- /dev/null +++ b/db/migrate/20260807101420_add_account_status_created_at_index_to_conversations.rb @@ -0,0 +1,12 @@ +class AddAccountStatusCreatedAtIndexToConversations < ActiveRecord::Migration[7.1] + disable_ddl_transaction! + + def change + # Serves account-scoped conversation lists sorted by created_at (e.g. "newest first"), + # which otherwise fall back to a backward scan of the global created_at index. + add_index :conversations, [:account_id, :status, :created_at], + name: 'index_conversations_on_account_id_status_created_at', + algorithm: :concurrently, + if_not_exists: true + end +end diff --git a/db/schema.rb b/db/schema.rb index aa88cc546..9491abbda 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[7.1].define(version: 2026_08_06_000000) do +ActiveRecord::Schema[7.1].define(version: 2026_08_07_101420) do # These extensions should be enabled to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm" @@ -854,6 +854,7 @@ ActiveRecord::Schema[7.1].define(version: 2026_08_06_000000) do t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true t.index ["account_id", "id"], name: "index_conversations_on_id_and_account_id" t.index ["account_id", "inbox_id", "status", "assignee_id"], name: "conv_acid_inbid_stat_asgnid_idx" + t.index ["account_id", "status", "created_at"], name: "index_conversations_on_account_id_status_created_at" 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"