@jpgilldev / steid

steid/migrations/20260829090000_add_repository_recency.sql
1.4 KBRaw
1-- Recency and pinning, the two things the profile page orders and leads with.
2--
3-- `updated_at` is unix seconds, moved when a push is authorized. Existing rows are
4-- stamped with the time this migration runs rather than left at 0: a repository that
5-- has been pushed to for months would otherwise read "updated 56 years ago" on the very
6-- page this column exists to order, and there is no honest value to recover — git could
7-- supply one, but at a fork per repository during a migration. "Migrated just now" is
8-- wrong by a bounded amount and self-corrects on the next push. 1970 is wrong forever
9-- and looks broken. Repositories that tie fall back to the name, so the listing is
10-- stable rather than arbitrary until the first push.
11--
12-- `pinned` defaults to false for every existing row, so nothing becomes the profile's
13-- lead without the owner saying so. Guessing a lead — the newest, the busiest — is the
14-- editorial decision the flag exists to hand to a person.
15--
16-- At most one pinned repository per owner is enforced in `update_repo`, not by a partial
17-- unique index here: the rule is "pinning this unpins that", and a constraint can only
18-- refuse, never unpin.
19alter table repositories add column updated_at integer not null default 0;
20alter table repositories add column pinned integer not null default 0;
21
22update repositories set updated_at = cast(strftime('%s', 'now') as integer);