-- Migration: 002_add_indexes
-- Description: Add performance indexes for common query patterns.

-- agents: status filtering, activity ordering
CREATE INDEX idx_agents_status        ON agents(status);
CREATE INDEX idx_agents_last_activity ON agents(last_activity DESC);
CREATE INDEX idx_agents_created_at    ON agents(created_at DESC);

-- sessions: agent session lookups, active session checks
CREATE INDEX idx_sessions_agent_id    ON sessions(agent_id);
CREATE INDEX idx_sessions_status      ON sessions(status);
CREATE INDEX idx_sessions_started_at  ON sessions(started_at DESC);

-- task_logs: agent task history, chronological ordering
CREATE INDEX idx_task_logs_agent_started ON task_logs(agent_id, started_at DESC);
CREATE INDEX idx_task_logs_status        ON task_logs(status);

-- agent_events: event stream queries
CREATE INDEX idx_agent_events_agent_created ON agent_events(agent_id, created_at DESC);
CREATE INDEX idx_agent_events_event_type    ON agent_events(event_type);

-- projects: status filtering, agent assignment
CREATE INDEX idx_projects_status   ON projects(status);
CREATE INDEX idx_projects_agent_id ON projects(agent_id);
CREATE INDEX idx_projects_created  ON projects(created_at DESC);
