-- 0002_job_history.sql

CREATE INDEX IF NOT EXISTS idx_job_logs_job_id ON job_logs(job_id);
CREATE INDEX IF NOT EXISTS idx_jobs_status_created ON jobs(status, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_jobs_sync_pair_id ON jobs(sync_pair_id);

CREATE TABLE IF NOT EXISTS cleanup_history (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    deleted_before  DATETIME NOT NULL,
    logs_purged     INTEGER NOT NULL DEFAULT 0,
    jobs_purged     INTEGER NOT NULL DEFAULT 0,
    executed_at     DATETIME DEFAULT CURRENT_TIMESTAMP
);
