-- Migration: Add stream_coverage table for smart gap detection
-- Run this in Supabase SQL editor

CREATE TABLE IF NOT EXISTS stream_coverage (
  id BIGSERIAL PRIMARY KEY,
  stream_id INTEGER REFERENCES streams(id) ON DELETE CASCADE,
  covered_from TIMESTAMPTZ NOT NULL,
  covered_to   TIMESTAMPTZ,
  source TEXT NOT NULL DEFAULT 'live',  -- 'live' | 'backfill' | 'vod_backfiller'
  created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_stream_coverage_stream_id ON stream_coverage(stream_id);
CREATE INDEX IF NOT EXISTS idx_stream_coverage_covered_from ON stream_coverage(covered_from);
