Skip to main content

max / makenotwork

1.1 KB · 16 lines History Blame Raw
1 -- Reconcile the memberships role CHECK with the `CommunityRole` domain enum,
2 -- which has only Owner/Moderator/Member. Migration 006 allowed a fourth value,
3 -- 'guest', that the enum cannot decode: a 'guest' row would fail the sqlx
4 -- decode and 500 every role lookup and member list for that community. Nothing
5 -- ever writes 'guest' (all inserts bind 'member' or a CommunityRole), so this
6 -- tightening is safe. 006's inline CHECK cannot be edited (applied-migration
7 -- checksum rule), so replace the auto-named constraint here.
8 ALTER TABLE memberships DROP CONSTRAINT IF EXISTS memberships_role_check;
9 -- Self-heal before tightening: nothing writes 'guest', but if a legacy row from
10 -- 006's wider CHECK somehow exists, the ADD CONSTRAINT below would hard-fail the
11 -- whole deploy on it. Fold any such row to 'member' first so the migration is
12 -- idempotent and can't be blocked by data (fuzz-2026-07-06 migration self-heal).
13 UPDATE memberships SET role = 'member' WHERE role = 'guest';
14 ALTER TABLE memberships ADD CONSTRAINT memberships_role_check
15 CHECK (role IN ('owner', 'moderator', 'member'));
16