Files
loki/scripts/backfill-project-registry.ts
CatoandClaude Fable 5.1 abb00b911c feat(register): one register for every project, joined from the owners of each fact (#610)
* feat(register): one register for every project, joined from the owners of each fact

"Which projects do we have, and which one has a site, a FleetCrown profile, an
OrangeCat profile, a Solon organisation?" had no answer. It had seven: apps.conf,
this database, OrangeCat's, Solon's, bitbaum's companies.json, the public footer's
config, and 24 markdown dossiers. Each is right about its own facts and wrong
about the others; joined by hand they disagreed on 5 names, the footer named a
host that had been renamed and missed 12 live ones, the showcase listed hosts
the hosting register did not know, and Caddy served 38 vhosts of which the
register knew 23.

This does not add an eighth list. It adds the JOIN, computed from the owners:

  src/lib/register/apps-conf.ts   the one parser for apps.conf (hosting SSOT)
  src/lib/register/build.ts       pure join keyed on the canonical slug
  src/lib/register/solon.ts       Solon membership via its public org endpoint,
                                  reported UNCHECKED (not "none") when unreachable
  GET /api/fleet/register         public JSON — consumers derive, never copy
  /fleet                          the same join, rendered

The join key is the repository name. Names have drifted into several spellings
(aoz-housing/aoz-wohnen, datacat/datacat-web, s-ink/sink, sbb-fundbuero/
sbb-lost-found, wild-spirit/annushka); `canonicalSlug` folds every alias that
has actually bitten, and each is pinned by a test. The durable fix is three
nullable columns on user_projects — slug, hosted_app, solon_org_slug — with
scripts/backfill-project-registry.ts to assign them once (drizzle/0065; the
applier is filename-based, matching how 0064 was shipped).

The footer stops being a list anyone edits. src/config/fleet-sites.ts is now
GENERATED from apps.conf by scripts/generate-fleet-sites.ts (the footer is a
client component and cannot read the register at render, and Atlas needs static
anchors), with editorial copy kept in fleet-site-copy.ts keyed by slug. A gate,
scripts/test/fleet-sites-derived.ts, fails the moment the file drifts.

apps.conf itself gets two corrections found by comparing it with the box:
evig (live on 4004 from the main Caddyfile, never registered) and
hirnli.orangecat.ch, which revamp-info's app serves.

Not done here, on purpose: the bitbaum showcase still renders its own
companies.json — it moves to the API once this is live; annushka and bitbaum are
static Caddy roots with no app process and do not fit the register's app shape.

Verified: 145/145 unit files (24 new assertions in fleet-register, drift gate
green), tsc clean, register gates (port-alloc, register-reality, client-ledger)
green with the new rows.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Z7YRpgsEtNjRqr1usHMQY

* fix(register): evig row names its host database, revampit

The deploy-ready gate found drizzle migrations in the evig checkout and a
db of '-', which is the shape that let botsmann serve PGRST205 for months.
evig is not deployed by deploy.sh at all — its own workflow applies its
migrations — but the register should still say which database that is.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Z7YRpgsEtNjRqr1usHMQY

* fix(watchdog): evig left the hand-list the day it entered the register

The hand-list is built to die one row at a time: the test that failed is
the one that forces a duplicate out the moment apps.conf registers it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Z7YRpgsEtNjRqr1usHMQY

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-11 00:23:03 -07:00

61 lines
2.1 KiB
TypeScript

#!/usr/bin/env -S npx tsx
/**
* backfill-project-registry — give every existing project its canonical slug
* and its apps.conf link, once.
*
* `slug` = the repository name (from git_url), else the display name folded
* through the alias table. `hosted_app` = the apps.conf row whose canonical
* slug matches. Never overwrites a value already set; prints what it would do
* with --dry-run. Runs where the production database is reachable (the box).
*
* DATABASE_URL=… npx tsx scripts/backfill-project-registry.ts [--dry-run]
*/
import { eq, isNull, and } from "drizzle-orm";
import { db } from "@/db";
import { userProjects } from "@/db/schema/user-projects";
import { readAppsConf } from "@/lib/register/apps-conf";
import { canonicalSlug, repoFromGitUrl } from "@/lib/register/build";
async function main() {
const dry = process.argv.includes("--dry-run");
const apps = readAppsConf();
const hostedBySlug = new Map(apps.map((a) => [canonicalSlug(a.name), a.name]));
const rows = await db
.select({
id: userProjects.id,
name: userProjects.name,
gitUrl: userProjects.gitUrl,
slug: userProjects.slug,
hostedApp: userProjects.hostedApp,
})
.from(userProjects)
.where(and(isNull(userProjects.slug)));
let updated = 0;
const seen = new Set<string>();
for (const r of rows) {
const slug = canonicalSlug(repoFromGitUrl(r.gitUrl) || r.name);
if (seen.has(slug)) {
console.warn(`skip ${r.name}: slug "${slug}" already assigned this run — resolve by hand`);
continue;
}
seen.add(slug);
const hostedApp = r.hostedApp ?? hostedBySlug.get(slug) ?? null;
console.log(
`${dry ? "would set" : "set"} ${r.name.padEnd(34)} slug=${slug.padEnd(24)} hosted_app=${hostedApp ?? "-"}`,
);
if (!dry) {
await db.update(userProjects).set({ slug, hostedApp }).where(eq(userProjects.id, r.id));
updated++;
}
}
console.log(`${dry ? "dry-run: " : ""}${rows.length} without slug, ${updated} updated`);
process.exit(0);
}
main().catch((e) => {
console.error(e instanceof Error ? e.message : String(e));
process.exit(1);
});