-- Migration: FK Indexes
-- Date: 2026-01-22
-- Description: Add missing indexes to foreign key columns for better query performance

-- HIGH PRIORITY: Frequently queried tables
CREATE INDEX IF NOT EXISTS idx_lead_notes_lead_id ON lead_notes(lead_id);
CREATE INDEX IF NOT EXISTS idx_conversions_lead_id ON conversions(lead_id);
CREATE INDEX IF NOT EXISTS idx_sequence_enrollments_lead_id ON sequence_enrollments(lead_id);

-- MEDIUM PRIORITY: Sequence system and call recordings
CREATE INDEX IF NOT EXISTS idx_sequence_enrollments_sequence_id ON sequence_enrollments(sequence_id);
CREATE INDEX IF NOT EXISTS idx_sequence_steps_sequence_id ON sequence_steps(sequence_id);
CREATE INDEX IF NOT EXISTS idx_call_recordings_communication_id ON call_recordings(communication_id);

-- LOW PRIORITY: Less frequently queried tables
CREATE INDEX IF NOT EXISTS idx_sequence_steps_template_id ON sequence_steps(template_id);
CREATE INDEX IF NOT EXISTS idx_voice_commands_lead_id ON voice_commands(affected_lead_id);
CREATE INDEX IF NOT EXISTS idx_ideas_lead_id ON ideas(lead_id);
CREATE INDEX IF NOT EXISTS idx_detected_friction_suggestion_id ON detected_friction(linked_suggestion_id);
