CREATE TABLE IF NOT EXISTS repo_commit_status (
    id UUID PRIMARY KEY,
    repo UUID NOT NULL REFERENCES repo(id) ON DELETE CASCADE,
    commit_sha TEXT NOT NULL,
    state TEXT NOT NULL CHECK (state IN ('pending', 'success', 'failure', 'error')),
    target_url TEXT,
    description TEXT,
    context TEXT NOT NULL DEFAULT 'default',
    creator UUID NOT NULL REFERENCES "user"(id),
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_commit_status_repo_sha ON repo_commit_status(repo, commit_sha);
CREATE INDEX IF NOT EXISTS idx_commit_status_context ON repo_commit_status(repo, commit_sha, context);
