| 1 | -- Pages know what they describe, and projects' docs folders in Docs |
| 2 | -- (docs/WORKSPACE.md, "Docs"; services/docs src/staleness.ts and |
| 3 | -- src/repo-spaces.ts). |
| 4 | |
| 5 | -- Code a page cites: from its text (the editor's citation chips and links |
| 6 | -- to files in a repository), rebuilt on each save; and from its header's |
| 7 | -- "Describes" list. `repo` is `owner/name`, lowercased; `path` a file, a |
| 8 | -- folder or a glob. |
| 9 | CREATE TABLE citations ( |
| 10 | page_id TEXT NOT NULL REFERENCES pages (id) ON DELETE CASCADE, |
| 11 | repo TEXT NOT NULL, |
| 12 | path TEXT NOT NULL, |
| 13 | kind TEXT NOT NULL CHECK (kind IN ('path', 'symbol', 'endpoint', 'env')), |
| 14 | label TEXT NOT NULL DEFAULT '', |
| 15 | ref TEXT, |
| 16 | source TEXT NOT NULL CHECK (source IN ('body', 'header')), |
| 17 | PRIMARY KEY (page_id, source, repo, path, kind, label) |
| 18 | ); |
| 19 | CREATE INDEX citations_repo ON citations (repo); |
| 20 | |
| 21 | -- Changes that touched code a page cites: one row per page and commit (a |
| 22 | -- merge is told twice, as `git.push` and as `pull.merged`; both land on |
| 23 | -- the same row, and the pull request names it). Open until someone marks |
| 24 | -- the page current (`cleared_at`). |
| 25 | CREATE TABLE page_changes ( |
| 26 | page_id TEXT NOT NULL REFERENCES pages (id) ON DELETE CASCADE, |
| 27 | repo TEXT NOT NULL, |
| 28 | repo_id TEXT NOT NULL, |
| 29 | commit_sha TEXT NOT NULL, |
| 30 | pull_number INTEGER, |
| 31 | pull_title TEXT, |
| 32 | -- The cited paths it changed, as JSON. |
| 33 | paths TEXT NOT NULL DEFAULT '[]', |
| 34 | detected_at TEXT NOT NULL, |
| 35 | cleared_at TEXT, |
| 36 | cleared_by TEXT, |
| 37 | PRIMARY KEY (page_id, repo, commit_sha) |
| 38 | ); |
| 39 | CREATE INDEX page_changes_open ON page_changes (page_id) WHERE cleared_at IS NULL; |
| 40 | CREATE INDEX page_changes_recent ON page_changes (detected_at) WHERE cleared_at IS NULL; |
| 41 | |
| 42 | -- An agent's suggestion that, once accepted, marks the page current. |
| 43 | ALTER TABLE suggestions ADD COLUMN marks_current INTEGER NOT NULL DEFAULT 0; |
| 44 | |
| 45 | -- A repository's docs folder shown in a workspace's Docs. |
| 46 | CREATE TABLE repo_spaces ( |
| 47 | id TEXT PRIMARY KEY, |
| 48 | workspace_id TEXT NOT NULL, |
| 49 | repo_id TEXT NOT NULL, |
| 50 | -- `owner/name`, lowercased, as it is named now. |
| 51 | repo TEXT NOT NULL, |
| 52 | default_branch TEXT NOT NULL, |
| 53 | -- The commit it was last read at. |
| 54 | commit_sha TEXT, |
| 55 | indexed_at TEXT, |
| 56 | added_by TEXT NOT NULL, |
| 57 | added_at TEXT NOT NULL, |
| 58 | UNIQUE (workspace_id, repo_id) |
| 59 | ); |
| 60 | CREATE INDEX repo_spaces_repo ON repo_spaces (repo_id); |
| 61 | |
| 62 | -- Its Markdown files as last read. `hash` is the blob's, so a push reads |
| 63 | -- only what changed. |
| 64 | CREATE TABLE repo_files ( |
| 65 | space_id TEXT NOT NULL REFERENCES repo_spaces (id) ON DELETE CASCADE, |
| 66 | path TEXT NOT NULL, |
| 67 | hash TEXT NOT NULL, |
| 68 | title TEXT NOT NULL, |
| 69 | markdown TEXT NOT NULL, |
| 70 | PRIMARY KEY (space_id, path) |
| 71 | ); |
| 72 | |
| 73 | -- Full text over them, beside pages_fts. |
| 74 | CREATE VIRTUAL TABLE repo_files_fts USING fts5 (space_id UNINDEXED, path UNINDEXED, title, body, tokenize = 'unicode61 remove_diacritics 2'); |