Files
claudetools/projects/msp-tools/guru-rmm/server/migrations/009_add_missing_indexes.sql
azcomputerguru 7c467b0d2c Add stub migrations and test results for Phase 1 tunnel
Stub migrations (005-008) satisfy sqlx requirement for previously
applied migrations that are missing source files in the codebase.
These migrations were applied in production but not committed.

Renumbered 005_add_missing_indexes to 009 to match production sequence.

Test results document confirms all Phase 1 tunnel API endpoints are
functioning correctly with proper error handling and HTTP status codes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-14 08:20:50 -07:00

27 lines
1.4 KiB
SQL

-- Migration: Add missing indexes for performance
-- These indexes were identified during code review as missing
-- Date: 2026-01-20
-- Index for agent API key lookups (authentication)
-- Supports legacy authentication where agents have their own api_key_hash
CREATE INDEX IF NOT EXISTS idx_agents_api_key_hash ON agents(api_key_hash);
-- Index for site API key lookups
-- Note: idx_sites_api_key already exists from migration 002, but using consistent naming
-- This is a no-op if the index already exists
CREATE INDEX IF NOT EXISTS idx_sites_api_key_hash ON sites(api_key_hash);
-- Index for command status queries (find all pending/running commands)
-- Note: idx_commands_agent_status exists for (agent_id, status)
-- This index is for querying by status alone (e.g., find all pending commands)
CREATE INDEX IF NOT EXISTS idx_commands_status ON commands(status);
-- Index for metrics time-range queries
-- Note: idx_metrics_agent_time already exists for (agent_id, timestamp DESC)
-- This is equivalent - creating with requested name for compatibility
CREATE INDEX IF NOT EXISTS idx_metrics_agent_timestamp ON metrics(agent_id, timestamp DESC);
-- Index for finding online agents quickly with last_seen ordering
-- Allows efficient queries like: WHERE status = 'online' ORDER BY last_seen DESC
CREATE INDEX IF NOT EXISTS idx_agents_status_last_seen ON agents(status, last_seen DESC);