-- CreateIndex
--
-- Guarded on `pg_extension` (installed, not merely available) rather than
-- run unconditionally: pg_trgm may have been skipped by the previous
-- migration on a host without postgresql-contrib, and `gin_trgm_ops` does
-- not exist without it. Without this index, name search still works — it
-- just runs as a plain ILIKE scan instead of a trigram-accelerated one,
-- which is unnoticeable below a few thousand rows and only matters at the
-- scale a shared-hosting demo will never reach.
DO $$
BEGIN
  IF EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_trgm') THEN
    EXECUTE 'CREATE INDEX "idx_leads_name_trgm" ON "leads" USING GIN ("full_name" gin_trgm_ops)';
    EXECUTE 'CREATE INDEX "idx_students_name_trgm" ON "students" USING GIN ("full_name" gin_trgm_ops)';
  END IF;
END $$;
