-- Migration 037: Add composite indexes for stock_observations
-- Optimises DISTINCT ON (transceiver_id, source_vendor_id) queries used
-- by GET /api/stock and GET /api/stock/summary.

-- Primary lookup index for "latest per (transceiver, vendor)" queries
CREATE INDEX IF NOT EXISTS idx_stock_tx_vendor_time
  ON stock_observations (transceiver_id, source_vendor_id, time DESC);

-- Partial index for "in-stock only" filter (used by /api/stock?in_stock=true)
CREATE INDEX IF NOT EXISTS idx_stock_in_stock
  ON stock_observations (in_stock, time DESC)
  WHERE in_stock = true;
