CREATE TABLE IF NOT EXISTS clone_jobs (
    id          INTEGER  PRIMARY KEY AUTOINCREMENT,
    repo_id     INTEGER  NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
    status      TEXT     NOT NULL CHECK(status IN ('pending','running','completed','failed')) DEFAULT 'pending',
    started_at  DATETIME,
    finished_at DATETIME,
    error       TEXT,
    created_at  DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_clone_jobs_repo_id ON clone_jobs(repo_id);
