23 lines
1.6 KiB
SQL
23 lines
1.6 KiB
SQL
-- M14: Global Search + Advanced Filter — performance indexes
|
|
-- Adds indexes to support ILIKE text search and advanced filter queries
|
|
-- across conversations, messages, and contacts.
|
|
|
|
-- Conversations: text search on status, labels, and account filtering
|
|
CREATE INDEX IF NOT EXISTS idx_conversations_account_status ON conversations (account_id, status);
|
|
CREATE INDEX IF NOT EXISTS idx_conversations_account_assignee ON conversations (account_id, assignee_id);
|
|
CREATE INDEX IF NOT EXISTS idx_conversations_account_priority ON conversations (account_id, priority);
|
|
CREATE INDEX IF NOT EXISTS idx_conversations_account_inbox ON conversations (account_id, inbox_id);
|
|
CREATE INDEX IF NOT EXISTS idx_conversations_labels ON conversations (account_id, labels);
|
|
|
|
-- Messages: text search on content, filter by type/sender/private
|
|
CREATE INDEX IF NOT EXISTS idx_messages_account_type ON messages (account_id, message_type);
|
|
CREATE INDEX IF NOT EXISTS idx_messages_account_sender ON messages (account_id, sender_type);
|
|
CREATE INDEX IF NOT EXISTS idx_messages_account_content_type ON messages (account_id, content_type);
|
|
CREATE INDEX IF NOT EXISTS idx_messages_account_private ON messages (account_id, private);
|
|
CREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages (conversation_id);
|
|
|
|
-- Contacts: text search on name, email, phone; filter by source
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_account_source ON contacts (account_id, source);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_name ON contacts (account_id, name);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_email ON contacts (account_id, email);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_phone ON contacts (account_id, phone_number); |