-- Per-run progress log for kn-API sweeps.
-- Workers append rows during run_region_sweep so the admin UI can show live
-- progress (started region X, fetched N objects, processing obj Y, ...).
-- Idempotent.

CREATE TABLE IF NOT EXISTS kn_scrape_log (
    log_id    BIGSERIAL PRIMARY KEY,
    run_id    BIGINT REFERENCES kn_scrape_runs(run_id) ON DELETE CASCADE,
    ts        TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    level     TEXT NOT NULL CHECK (level IN ('info', 'warn', 'error')),
    stage     TEXT,
    obj_id    INT,
    message   TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_kn_scrape_log_run_ts
    ON kn_scrape_log (run_id, ts DESC);

CREATE INDEX IF NOT EXISTS idx_kn_scrape_log_ts
    ON kn_scrape_log (ts DESC);
