steid

@jamesgill /

steid/migrations/20260906140200_create_labels.sql
SQL1.6 KBCode·Blame·History·Raw
1-- Labels: the short coloured words a repository sorts its issues with.
2--
3-- Scoped to a repository, not to the instance: `bug` here and `bug` there are different
4-- rows, so one owner renaming theirs cannot touch anybody else's. `unique (repo_id,
5-- name)` is what makes `?label=bug` on the issues list a URL that names one thing, and
6-- it is the backstop under the use case's own duplicate check — reaching it means two
7-- creations raced.
8--
9-- `colour` is one of eight palette **names** (`gray`, `red`, `orange`, `yellow`,
10-- `green`, `blue`, `purple`, `pink`), never a hex value. `plans/ui.md` says components
11-- refer to theme tokens and never to raw colours, and a hex column would put a raw
12-- colour in the database and then on the page: unable to follow a palette change, and
13-- free to be unreadable in one of the two colour schemes. Text rather than an integer
14-- so a row is readable in a shell, matching `issues.state`.
15--
16-- `description` is null rather than empty when absent, matching `repositories`.
17create table labels (
18 id text primary key,
19 repo_id text not null references repositories (id) on delete cascade,
20 name text not null,
21 colour text not null,
22 description text,
23 created_at integer not null,
24 unique (repo_id, name)
25);
26
27-- Every read of labels is "this repository's, by name" — the management page, the
28-- checkbox list on an issue, and resolving `?label=`. The unique index above already
29-- covers that prefix, so this one exists only for the ordering the listing asks for,
30-- which SQLite would otherwise sort in memory on every issues page.
31create index labels_repo_name on labels (repo_id, name);