Files
solon/drizzle/0003_org_founding.sql
CatoandClaude Opus 5 bd72e5ace0 feat(orgs): anyone may found an organization; everything after is voted (#166)
Solon could govern many organizations and shipped exactly one, because the only
way to create one was to write a SQL migration (drizzle/0001_seed_org1). That
does not survive a second builder, and it made Solon something the studio grants
rather than something people use.

WHERE THE LINE IS

Founding is permissionless; acting within an organization is governed. Requiring
a vote to create one is circular — there is no electorate to vote in yet — so the
founding seat is granted the way membership.ts already grants the genesis seat:
on proof, not permission. The founder signs with a Bitcoin key they control,
bound to their OrangeCat identity, and the organization, the founder's seat and
both audit events are written in ONE transaction. There is no instant when an
organization exists with an unclaimed founding seat somebody else could take.

ONE SEAT PER ORGANIZATION, NOT PER PERSON

members.oc_actor_id was globally unique, so an OrangeCat identity could sit on
exactly one roster ever — a builder who founded a second organization could not
be its founding member. It is now unique per organization, which keeps the
property that mattered (nobody holds two votes in one electorate) and drops the
one that was an accident. memberForActor() therefore takes an organization;
without that, a builder would be shown one organization's seat on another's
pages. Four call sites updated.

ATTRIBUTION IS CONSENT, NOT A NAME MATCH

Permissionless founding opens one door that must stay shut: anyone could found
`loki` and appear on a public register to govern a product they have nothing to
do with. So organizations.claimed_project is set only from a grant Loki signs
for the founder's own identity (src/lib/loki-grant.ts), checked against the
SESSION's actor id — never one taken from the request. Squatting a name costs a
vanity slug, never attribution. A grant that is present but invalid refuses the
founding outright rather than quietly creating an unattributed organization.

Organization #1 is backfilled as governing `orangecat` (0004) — it predates
grants, so it is reference data, the way the organization itself was.

AND THE 404 NOBODY OWNED

Loki's fleet map and the bitbaum studio site both link /orgs/<slug>. No such
page existed: every one of those links answered 404, including the link to
organization #1. /orgs/[slug] now serves the roster and the record, and
/api/orgs lists every organization so Loki can stop probing one name at a time.

PROVEN

CI ran ONE integration spec by name, so the membership spec guarding the
founding seat had never once run there. It now runs every *.integration.test.ts
— and caught this change's own regression on the first run, where the reworded
refusal no longer matched that spec's assertion.

23 integration assertions against a real database (atomicity, signature replay
across message types, the multi-organization constraint, grant forgery and
expiry, one organization per project, the founding cap) plus 116 unit tests.
pnpm run verify: green.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 00:43:15 -07:00

4 lines
402 B
SQL

DROP INDEX "members_oc_actor_id_key";--> statement-breakpoint
ALTER TABLE "organizations" ADD COLUMN "claimed_project" text;--> statement-breakpoint
CREATE UNIQUE INDEX "members_organization_id_oc_actor_id_key" ON "members" USING btree ("organization_id","oc_actor_id");--> statement-breakpoint
CREATE UNIQUE INDEX "organizations_claimed_project_key" ON "organizations" USING btree ("claimed_project");