-- Nexus 6.0 — Database Index Migration
-- Run this manually if create_all() didn't create the indexes.
-- Safe to run even if indexes already exist (will skip with "Duplicate key name" error).

-- Server list queries filter by is_online frequently (Dashboard, API list)
CREATE INDEX IF NOT EXISTS idx_servers_is_online ON servers (is_online);

-- Server list queries filter by category (sidebar tabs)
CREATE INDEX IF NOT EXISTS idx_servers_category ON servers (category);

-- Sync log queries filter by server_id + date range (logs page, server detail)
CREATE INDEX IF NOT EXISTS idx_sync_logs_srv_start ON sync_logs (server_id, started_at);

-- Login attempt queries filter by username + time (brute-force detection)
CREATE INDEX IF NOT EXISTS idx_login_attempts_username_time ON login_attempts (username, attempted_at);

-- Audit log queries filter by action + time (audit page)
CREATE INDEX IF NOT EXISTS idx_audit_logs_action_time ON audit_logs (action, created_at);

-- Push schedule queries filter by enabled (cron scheduler)
CREATE INDEX IF NOT EXISTS idx_push_schedules_enabled ON push_schedules (enabled);

-- Push retry queries filter by status + next_retry_at (retry engine)
CREATE INDEX IF NOT EXISTS idx_push_retry_pending ON push_retry_jobs (status, next_retry_at);