-- commit_summaries: auto-generated commit / PR markdown summaries.
CREATE TABLE commit_summaries (
    id           uuid PRIMARY KEY,
    workspace_id uuid NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
    worktree_id  uuid NULL,
    branch       text NOT NULL,
    commit_sha   text NOT NULL,
    kind         text NOT NULL DEFAULT 'commit' CHECK (kind IN ('commit','pr')),
    title        text,
    body_md      text NOT NULL,
    model        text,
    status       text NOT NULL DEFAULT 'pending' CHECK (status IN ('pending','completed','failed')),
    error        text,
    created_at   timestamptz NOT NULL DEFAULT now(),
    UNIQUE (workspace_id, commit_sha, kind)
);

CREATE INDEX idx_commit_summaries_ws ON commit_summaries (workspace_id, commit_sha);
