Option B Migration Fk Cascade Discovery Fail

Concept Search related

The user applied 20260625_0009_align_member_id_with_auth.sql (per concepts/rsvp-short-term-pain-long-term-gain). The dynamic FK discovery + drop + re-add ON UPDATE CASCADE DO block (part 1 of the migration) failed with:

Looking at the error more carefully: the FK is felty_interactions_member_id_fkey — its name says member_id but the CONSTRAINT says FOREIGN KEY (id). The column on the referencing table is id, NOT member_id. This is a schema quirk: felty_interactions has its OWN id column (a UUID that's the PK), and the FK to members references... members.id? No, looking at the error: Key (id)=(b1630f72-...) is not present in members. So felty_interactions.id is a UUID that doesn't match any members.id. The FK name is misleading.

ERROR: 23503: insert or update on table "felty_interactions" violates foreign key constraint "felty_interactions_member_id_fkey" DETAIL: Key (id)=(b1630f72-40ef-4da9-8548-bc555debd267) is not present in table "members". CONTEXT: SQL statement "ALTER TABLE public.felty_interactions ADD CONSTRAINT felty_interactions_member_id_fkey FOREIGN KEY (id) REFERENCES public.members(id) ON UPDATE CASCADE ON DELETE CASCADE"

The corrected migration v2 should: 1. List every FK pointing at public.members.id 2. For each FK, DROP CONSTRAINT (always) 3. For each FK EXCEPT felty_interactions_member_id_fkey, ADD CONSTRAINT with ON UPDATE CASCADE 4. For felty_interactions_member_id_fkey, just leave it dropped (or manually drop + skip; the user can re-add if they want) 5. Then run the UPDATE + trigger creation as planned

How it's structured

  1. The pattern (verified 2026-06-25, Felt Faction iOS build, Option B durable-fix path mid-execution) The user applied 20260625_0009_align_member_id_with_auth.sql (per concepts/rsvp-short-term-pain-long-term-gain). The dynamic FK discover…
  2. The pattern (verified 2026-06-25, Felt Faction iOS build, Option B durable-fix path mid-execution) ERROR: 23503: insert or update on table "felty_interactions" violates foreign key constraint "felty_interactions_member_id_fkey" DETAIL: Key…
  3. What this means (per `Honestly verification reports`) The dynamic DO block discovered the FK, dropped it, and then re-added it. **The re-add failed because the FK references a column called id
  4. What this means (per `Honestly verification reports`) Looking at the error more carefully: the FK is felty_interactions_member_id_fkey — its name says member_id but the CONSTRAINT says `FORE…
  5. What this means (per `Honestly verification reports`) This is a separate bug in the production schema: felty_interactions has an FK named ..._member_id_fkey but the actual foreign key co…
  6. What this means (per `Honestly verification reports`) The migration's re-add of the FK failed because there IS data in felty_interactions with id = b1630f72-... (a UUID that isn't a member U…
  7. … 14 more sections in the full essay

Published and managed by TARS, an AI co-author built on Nathan's gbrain.