CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
0063_multi_repo_refactors.sql
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 23d0abf | 1 | -- Multi-repo refactor agent — one English request fan-outs to coordinated |
| 2 | -- PRs across every affected repo, then merges them in order once all PRs | |
| 3 | -- are green + approved. | |
| 4 | -- | |
| 5 | -- The classic example: "rename `getUserById` to `findUser`". A user owns | |
| 6 | -- 8 repos that import the helper; the agent walks each of them, opens an | |
| 7 | -- AI-authored PR with the rename, and tags every PR with a single | |
| 8 | -- `multi-repo:refactor:<id>` label so the UI can group them. | |
| 9 | -- | |
| 10 | -- Two tables: | |
| 11 | -- `multi_repo_refactors` — the parent record. One row per user-issued | |
| 12 | -- request. Lifecycle: planning → building → | |
| 13 | -- ready_for_review → merged | failed. | |
| 14 | -- `multi_repo_refactor_prs` — one row per affected repo. Holds the FK to | |
| 15 | -- the `pull_requests` row (nullable until the | |
| 16 | -- per-repo PR is actually opened) plus the | |
| 17 | -- per-repo status (pending|building|opened| | |
| 18 | -- failed) and an error message if the build | |
| 19 | -- step bailed for that repo. | |
| 20 | -- | |
| 21 | -- Coordinated merge: when the user (or autopilot) triggers a merge on the | |
| 22 | -- parent refactor, the orchestrator walks the child rows in insertion order; | |
| 23 | -- if any child fails the rest stay open so the user can intervene. The | |
| 24 | -- merge driver lives in `src/lib/multi-repo-refactor.ts`. | |
| 25 | ||
| 26 | CREATE TABLE IF NOT EXISTS multi_repo_refactors ( | |
| 27 | id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | |
| 28 | owner_user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE, | |
| 29 | title text NOT NULL, | |
| 30 | description text NOT NULL, | |
| 31 | -- 'planning' | 'building' | 'ready_for_review' | 'merged' | 'failed' | |
| 32 | status text NOT NULL DEFAULT 'planning', | |
| 33 | created_at timestamp NOT NULL DEFAULT now(), | |
| 34 | updated_at timestamp NOT NULL DEFAULT now() | |
| 35 | ); | |
| 36 | ||
| 37 | CREATE INDEX IF NOT EXISTS multi_repo_refactors_owner | |
| 38 | ON multi_repo_refactors (owner_user_id, created_at DESC); | |
| 39 | ||
| 40 | CREATE INDEX IF NOT EXISTS multi_repo_refactors_status | |
| 41 | ON multi_repo_refactors (status, updated_at DESC); | |
| 42 | ||
| 43 | CREATE TABLE IF NOT EXISTS multi_repo_refactor_prs ( | |
| 44 | id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | |
| 45 | refactor_id uuid NOT NULL REFERENCES multi_repo_refactors(id) ON DELETE CASCADE, | |
| 46 | repository_id uuid NOT NULL REFERENCES repositories(id) ON DELETE CASCADE, | |
| 47 | -- Nullable: stays NULL until the per-repo PR is actually opened. | |
| 48 | pull_request_id uuid REFERENCES pull_requests(id) ON DELETE SET NULL, | |
| 49 | -- 'pending' | 'building' | 'opened' | 'failed' | |
| 50 | status text NOT NULL DEFAULT 'pending', | |
| 51 | error_message text, | |
| 52 | created_at timestamp NOT NULL DEFAULT now(), | |
| 53 | updated_at timestamp NOT NULL DEFAULT now() | |
| 54 | ); | |
| 55 | ||
| 56 | -- One row per (refactor, repo). A refactor never targets the same repo twice. | |
| 57 | CREATE UNIQUE INDEX IF NOT EXISTS multi_repo_refactor_prs_unique | |
| 58 | ON multi_repo_refactor_prs (refactor_id, repository_id); | |
| 59 | ||
| 60 | CREATE INDEX IF NOT EXISTS multi_repo_refactor_prs_refactor | |
| 61 | ON multi_repo_refactor_prs (refactor_id, status); | |
| 62 | ||
| 63 | CREATE INDEX IF NOT EXISTS multi_repo_refactor_prs_repo | |
| 64 | ON multi_repo_refactor_prs (repository_id); |