pr_01m47d15m3e54sn21z27rpy5n9/services/work/migrations/0001_init.sql
| 1 | -- Issues, pull requests, comments and sessions. |
| 2 | -- Every timestamp is RFC 3339 UTC text. |
| 3 | |
| 4 | -- Issues and pull requests share one sequence of numbers per repository. |
| 5 | CREATE TABLE counters ( |
| 6 | repo_id TEXT PRIMARY KEY, |
| 7 | last INTEGER NOT NULL |
| 8 | ); |
| 9 | |
| 10 | CREATE TABLE issues ( |
| 11 | id TEXT PRIMARY KEY, |
| 12 | repo_id TEXT NOT NULL, |
| 13 | number INTEGER NOT NULL, |
| 14 | title TEXT NOT NULL, |
| 15 | body TEXT NOT NULL, |
| 16 | -- JSON array of label names. |
| 17 | labels TEXT NOT NULL DEFAULT '[]', |
| 18 | -- JSON array of commands. |
| 19 | checks TEXT NOT NULL DEFAULT '[]', |
| 20 | state TEXT NOT NULL DEFAULT 'open', |
| 21 | -- Why it was closed: completed or not_planned. |
| 22 | reason TEXT, |
| 23 | -- The number of the pull request whose merge closed it. |
| 24 | resolved_by INTEGER, |
| 25 | author_id TEXT NOT NULL, |
| 26 | author_name TEXT NOT NULL, |
| 27 | created_at TEXT NOT NULL, |
| 28 | updated_at TEXT NOT NULL, |
| 29 | closed_at TEXT, |
| 30 | UNIQUE (repo_id, number) |
| 31 | ); |
| 32 | CREATE INDEX issues_by_state ON issues (repo_id, state, number); |
| 33 | |
| 34 | CREATE TABLE pulls ( |
| 35 | id TEXT PRIMARY KEY, |
| 36 | repo_id TEXT NOT NULL, |
| 37 | number INTEGER NOT NULL, |
| 38 | -- The issue it is for, if any, and that issue's number. |
| 39 | issue_id TEXT REFERENCES issues (id), |
| 40 | issue_number INTEGER, |
| 41 | title TEXT NOT NULL, |
| 42 | body TEXT, |
| 43 | agent TEXT NOT NULL, |
| 44 | runtime TEXT NOT NULL, |
| 45 | status TEXT NOT NULL DEFAULT 'draft', |
| 46 | -- Where the change is: a fork made for the pull request, or a branch of |
| 47 | -- the repository itself. |
| 48 | fork_repo_id TEXT UNIQUE, |
| 49 | fork_namespace TEXT, |
| 50 | fork_name TEXT, |
| 51 | source_branch TEXT, |
| 52 | head_commit TEXT, |
| 53 | -- What the branch pointed to before a merged pull request landed. |
| 54 | merge_base TEXT, |
| 55 | merged_by TEXT, |
| 56 | merged_at TEXT, |
| 57 | -- The pull request merged instead of this one. |
| 58 | superseded_by INTEGER, |
| 59 | -- JSON array of { path, additions, deletions }: what it changes, as of |
| 60 | -- its latest push. NULL until first worked out. |
| 61 | files TEXT, |
| 62 | -- The latest run of the issue's acceptance checks, and where it stands. |
| 63 | check_run_id TEXT, |
| 64 | check_status TEXT, |
| 65 | author_id TEXT NOT NULL, |
| 66 | author_name TEXT NOT NULL, |
| 67 | created_at TEXT NOT NULL, |
| 68 | updated_at TEXT NOT NULL, |
| 69 | UNIQUE (repo_id, number) |
| 70 | ); |
| 71 | CREATE INDEX pulls_by_status ON pulls (repo_id, status, number); |
| 72 | CREATE INDEX pulls_by_issue ON pulls (issue_id); |
| 73 | CREATE INDEX pulls_by_author ON pulls (author_id, status); |
| 74 | |
| 75 | -- On an issue or a pull request: the two share numbers. |
| 76 | CREATE TABLE comments ( |
| 77 | id TEXT PRIMARY KEY, |
| 78 | repo_id TEXT NOT NULL, |
| 79 | number INTEGER NOT NULL, |
| 80 | author_id TEXT NOT NULL, |
| 81 | author_name TEXT NOT NULL, |
| 82 | body TEXT NOT NULL, |
| 83 | -- For a comment on one line of a pull request's change: the file, and |
| 84 | -- the line as numbered after the change. |
| 85 | path TEXT, |
| 86 | line INTEGER, |
| 87 | -- A reviewer's decision: approve or request_changes. |
| 88 | verdict TEXT, |
| 89 | created_at TEXT NOT NULL |
| 90 | ); |
| 91 | CREATE INDEX comments_by_subject ON comments (repo_id, number, id); |
| 92 | |
| 93 | CREATE TABLE session_entries ( |
| 94 | pull_id TEXT NOT NULL REFERENCES pulls (id), |
| 95 | seq INTEGER NOT NULL, |
| 96 | kind TEXT NOT NULL, |
| 97 | text TEXT NOT NULL, |
| 98 | tool TEXT, |
| 99 | -- The fork's head when the entry was recorded: links reasoning to code. |
| 100 | "commit" TEXT, |
| 101 | at TEXT NOT NULL, |
| 102 | PRIMARY KEY (pull_id, seq) |
| 103 | ); |
| 104 | |
| 105 | -- Runs of an issue's acceptance checks against a pull request's head. |
| 106 | CREATE TABLE check_runs ( |
| 107 | id TEXT PRIMARY KEY, |
| 108 | pull_id TEXT NOT NULL REFERENCES pulls (id), |
| 109 | head_commit TEXT NOT NULL, |
| 110 | -- queued, running, passed, failed or errored. |
| 111 | status TEXT NOT NULL DEFAULT 'queued', |
| 112 | -- JSON array of { command, passed, exitCode, output, durationMs }. |
| 113 | results TEXT NOT NULL DEFAULT '[]', |
| 114 | error TEXT, |
| 115 | -- SHA-256 of the token the sandbox reports with. |
| 116 | token_hash TEXT NOT NULL, |
| 117 | created_at TEXT NOT NULL, |
| 118 | finished_at TEXT |
| 119 | ); |
| 120 | CREATE INDEX check_runs_by_pull ON check_runs (pull_id, id); |
| 121 | |
| 122 | -- Reviews of a pull request being written by a g1t agent in a sandbox. |
| 123 | CREATE TABLE review_runs ( |
| 124 | id TEXT PRIMARY KEY, |
| 125 | pull_id TEXT NOT NULL REFERENCES pulls (id), |
| 126 | -- SHA-256 of the token the sandbox reports with. |
| 127 | token_hash TEXT NOT NULL, |
| 128 | created_at TEXT NOT NULL, |
| 129 | finished_at TEXT |
| 130 | ); |
| 131 | CREATE INDEX review_runs_by_pull ON review_runs (pull_id, id); |