-- Index the `sync_chapter_list` in-flight path used by the admin sync-state
-- derivation (overview `manga_stats` + the Mangas tab listing).
--
-- A manga is "in_progress" if a pending/running job targets it. For the
-- `sync_manga` kind that join is already covered by
-- crawler_jobs_sync_manga_key_idx (0020). The OTHER kind, `sync_chapter_list`,
-- carries the target `manga_id` directly in its payload and had NO index — so
-- the EXISTS fell back to a full seqscan of crawler_jobs. Per manga that is
-- cheap; across the whole library (overview scans every manga) it is O(mangas
-- x jobs), and the disabled-analysis backlog (thousands of pending
-- `analyze_page` rows that can never match this filter) inflates every scan.
--
-- Partial on the same `state IN ('pending','running') AND kind = ...`
-- predicate as the sibling indexes so it stays tiny (only in-flight list
-- jobs) and Postgres can probe it instead of scanning. Mirrors 0020.
--
-- Not CONCURRENTLY: sqlx::migrate! wraps each migration in a transaction;
-- CREATE INDEX CONCURRENTLY can't run inside one. The table is small at our
-- scale so a brief build lock on deploy is safe. IF NOT EXISTS keeps it
-- idempotent with any operator who pre-created it on the live DB.
CREATE INDEX IF NOT EXISTS crawler_jobs_sync_chapter_list_manga_idx
    ON crawler_jobs ((payload->>'manga_id'))
 WHERE state IN ('pending', 'running')
   AND payload->>'kind' = 'sync_chapter_list';
