feat(db): add cli_session_pull_requests side table + migration#2872
Conversation
…tracking Adds a new side table to store GitHub PR metadata associated with cloud-agent-next sessions. Keeping this separate from cli_sessions_v2 avoids adding 6 sparse nullable columns to an already-wide table and allows webhook-driven PR writes to evolve independently. Also adds indexes on cli_sessions_v2 needed by upcoming beads: - (git_url, git_branch) for webhook session lookup - unique on session_id to support the FK from the new side table Bead b7954dba — convoy dbccdbdf.
|
Refinery code review passed. Checked:
One real caveat (author already flagged this in Reviewer Notes and I agree with the risk framing): the new A strictly-cleaner alternative would have been a composite FK Migration SQL was manually reordered (drizzle-kit emitted FK before index). This is noted by the author and is required for correctness; AGENTS.md's 'never hand-edit migration SQL' rule is in tension with 'generated migration fails' reality here — the reorder is defensible but a team lead may want to bless this precedent. |
Code Review SummaryStatus: 1 Issues Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)WARNING
Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (2 files)
Reviewed by gpt-5.5-2026-04-23 · 831,878 tokens |
25bf277
into
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head
feat(db): add cli_session_pull_requests side table for associated PR tracking Adds a new side table to store GitHub PR metadata associated with cloud-agent-next sessions. Keeping this separate from cli_sessions_v2 avoids adding 6 sparse nullable columns to an already-wide table and allows webhook-driven PR writes to evolve independently. Also adds indexes on cli_sessions_v2 needed by upcoming beads: - (git_url, git_branch) for webhook session lookup - unique on session_id to support the FK from the new side table Bead b7954dba — convoy dbccdbdf. Co-authored-by: Toast (gastown) <Toast@gastown.local>
feat(db): add cli_session_pull_requests side table for associated PR tracking Adds a new side table to store GitHub PR metadata associated with cloud-agent-next sessions. Keeping this separate from cli_sessions_v2 avoids adding 6 sparse nullable columns to an already-wide table and allows webhook-driven PR writes to evolve independently. Also adds indexes on cli_sessions_v2 needed by upcoming beads: - (git_url, git_branch) for webhook session lookup - unique on session_id to support the FK from the new side table Bead b7954dba — convoy dbccdbdf. Co-authored-by: Toast (gastown) <Toast@gastown.local>
Summary
cli_session_pull_requestsside table (session_id PK, FK tocli_sessions_v2.session_idON DELETE CASCADE) with columns for PR URL, number, state, title, head SHA, and sync timestamps.pr_stateandpr_numberfor future query patterns.cli_sessions_v2: a(git_url, git_branch)index for webhook lookup (bead 2) and a unique index onsession_idneeded to support the FK target.0106_gorgeous_iron_patriot.sqlvia drizzle-kit. Statements were reordered so the unique index is created before the FK references it (PostgreSQL requires the referenced column to be unique when the FK is added).Bead 0 of 5 in the 'Associated PR for cloud-agent-next session' convoy. Schema + migration only; consumers land in later beads.
Verification
POSTGRES_URL=... pnpm drizzle generate— produces no further diff after the edits.pnpm --filter @kilocode/db typecheckpasses.pnpm --filter web typecheckpasses.CREATE UNIQUE INDEXoncli_sessions_v2.session_idis emitted before theALTER TABLE … ADD CONSTRAINT … FOREIGN KEYso the FK target is present when PostgreSQL creates the constraint.Visual Changes
N/A — schema-only change.
Reviewer Notes
cli_sessions_v2has a composite PK(session_id, kilo_user_id), sosession_idalone is not unique out of the box. To satisfy the bead'ssession_id references cli_sessions_v2(session_id)spec, a unique indexUQ_cli_sessions_v2_session_idis added. If there are existing rows where the samesession_idis shared across users, this migration will fail — worth a quick spot check before merge, but the practice in the codebase (e.g.code-reviews-router.tslooks up kilo_user_id from session_id alone) already implies uniqueness.