g1t/services/repos/migrations/0015_about.sql
| 1 | -- A repository's About (src/stats.rs, src/stars.rs, src/releases.rs). |
| 2 | -- Additive; nothing is backfilled: what is read from a repository's files |
| 3 | -- and history is worked out the first time its Files page is viewed. |
| 4 | |
| 5 | -- What was worked out from the default branch at one commit: one row per |
| 6 | -- repository, replaced when its head moves. |
| 7 | -- |
| 8 | -- commit_hash: the commit it describes; null before the first is done. |
| 9 | -- started_ms: milliseconds since the epoch; set while one is being worked |
| 10 | -- out, so only one runs at a time (a run older than two minutes is |
| 11 | -- taken to have died). |
| 12 | -- license: JSON `License`, or null. security_policy: its path, or null. |
| 13 | -- languages: JSON array of `LanguageShare`. |
| 14 | -- contributors_total, contributors_top: how many, and the most active |
| 15 | -- (JSON array of `Contributor` without weeks), for the Files page. |
| 16 | -- contributors: JSON `{ commits, contributors, weeks }`, the whole answer |
| 17 | -- for the Contributors page. |
| 18 | -- partial: 1 when the files or history were too large to read in full. |
| 19 | CREATE TABLE repo_stats ( |
| 20 | repo_id TEXT PRIMARY KEY, |
| 21 | commit_hash TEXT, |
| 22 | computed_at TEXT, |
| 23 | started_ms INTEGER, |
| 24 | partial INTEGER NOT NULL DEFAULT 0, |
| 25 | license TEXT, |
| 26 | security_policy TEXT, |
| 27 | languages TEXT NOT NULL DEFAULT '[]', |
| 28 | contributors_total INTEGER NOT NULL DEFAULT 0, |
| 29 | contributors_top TEXT NOT NULL DEFAULT '[]', |
| 30 | contributors TEXT |
| 31 | ); |
| 32 | |
| 33 | -- Who starred what. user_id: the account's id; names are looked up when |
| 34 | -- shown, so a renamed account keeps its stars. |
| 35 | CREATE TABLE repo_stars ( |
| 36 | repo_id TEXT NOT NULL, |
| 37 | user_id TEXT NOT NULL, |
| 38 | created_at TEXT NOT NULL, |
| 39 | PRIMARY KEY (repo_id, user_id) |
| 40 | ); |
| 41 | CREATE INDEX repo_stars_user ON repo_stars (user_id, created_at); |
| 42 | CREATE INDEX repo_stars_newest ON repo_stars (repo_id, created_at); |
| 43 | |
| 44 | -- Releases: a tag with a title and notes. One per tag. |
| 45 | -- |
| 46 | -- target: the commit the tag named when the release was made. |
| 47 | -- author_id, author: who made it, by id and by username then. |
| 48 | -- published_at: null while it is a draft. |
| 49 | CREATE TABLE releases ( |
| 50 | id TEXT PRIMARY KEY, |
| 51 | repo_id TEXT NOT NULL, |
| 52 | tag_name TEXT NOT NULL, |
| 53 | target TEXT NOT NULL, |
| 54 | name TEXT, |
| 55 | body TEXT NOT NULL DEFAULT '', |
| 56 | draft INTEGER NOT NULL DEFAULT 0, |
| 57 | prerelease INTEGER NOT NULL DEFAULT 0, |
| 58 | author_id TEXT, |
| 59 | author TEXT, |
| 60 | created_at TEXT NOT NULL, |
| 61 | published_at TEXT, |
| 62 | updated_at TEXT NOT NULL |
| 63 | ); |
| 64 | CREATE UNIQUE INDEX releases_tag ON releases (repo_id, tag_name); |
| 65 | CREATE INDEX releases_newest ON releases (repo_id, created_at); |