-- Migration: Background jobs — GIN index on metadata
-- Description: Supports the "latest job for a session" lookup on the online-session
--              GET responses, which filters background_jobs by containment on
--              metadata->'sessionIds' (e.g. metadata @> '{"sessionIds":[123]}'). A job
--              can target multiple sessions at once (bulk registration across several
--              sessions), so session scope lives in this jsonb array rather than a
--              dedicated column. Indexing the whole jsonb column (default jsonb_ops)
--              supports the @> containment operator used by that query.
-- Idempotent — safe to re-run.

CREATE INDEX IF NOT EXISTS idx_background_jobs_metadata ON background_jobs USING GIN (metadata);
