-- Performance indexes for hot read paths.
-- Idempotent (IF NOT EXISTS). Safe to re-run. Targets the exact filter+sort
-- shapes of the highest-traffic queries that existing Prisma @@index entries
-- do not fully cover. No schema/model changes — additive indexes only.

-- 1. listPublicDirectory (homepage rails, /pretraga, listing pages, company
--    detail "similar/nearby" rails). Query filters Company by (status, type)
--    and orders by (isFeatured DESC, updatedAt DESC, createdAt DESC).
--    Existing schema only has single-column indexes on status / type /
--    isFeatured, so the planner cannot satisfy the combined filter+sort.
CREATE INDEX IF NOT EXISTS "company_status_type_featured_updated_idx"
  ON "Company" ("status", "type", "isFeatured", "updatedAt" DESC, "createdAt" DESC);

-- 2. getActiveBoostMap — called for every directory render. Filters
--    BoostPurchase by (entityType, status) with an expiresAt range.
--    Existing indexes lead with status or put entityId before status; none
--    lead with (entityType, status).
CREATE INDEX IF NOT EXISTS "boostpurchase_entitytype_status_expiresat_idx"
  ON "BoostPurchase" ("entityType", "status", "expiresAt");
