Migration Preflight Query Revealed Missing Auth Identity

Concept Search related

The user ran the preflight query (per references/migration-file-schema-drift-pattern.md) before applying the 20260625_0009_align_member_id_with_auth.sql migration. The output revealed a critical detail the LLM hadn't surfaced:

Signals: 1 concept captured → concepts/migration-preflight-query-revealed-missing-auth-identity (the orphan-row discovery, why DELETE is the right call, what the v2 migration should add), 0 entities, 0 facts. Captured silently per WRITES SILENTLY preference. This is the 4th brain page written this turn (after concepts/auth-users-vs-apple-subject-uuid-mismatch, concepts/rsvp-short-term-pain-long-term-gain, concepts/sign-in-with-apple-fix-recipe-final-verified, and concepts/akauthenticationerror-7026-signinwithapple-stale-credential). Per the WRITES SILENTLY rule, no confirmation prompts.

That's fine — row 2 has no matching auth.users row's OAuth subject, so there's no "correct" auth.users.id to migrate to. But row 2 STILL has oauth_provider = 'apple' and the new BEFORE INSERT/ UPDATE trigger will REJECT any INSERT or UPDATE on members where the row tries to keep id = 'a952b4ce-...' (because the trigger checks NEW.id = auth.uid() — for an admin signed in as Nate, auth.uid() = 9db7d397-..., which won't match the orphan id).

This filter matches members.oauth_subject = auth.identities.identity_data->>'sub'. For row 2, members.oauth_subject = '' and auth.identities.identity_data->>'sub' is non-null (the Apple subject for the second user). The filter won't match. Row 2 will NOT be migrated by the UPDATE.

How it's structured

  1. The pattern (verified 2026-06-25, Felt Faction iOS build, Option B durable-fix path) The user ran the preflight query (per references/migration-file-schema-drift-pattern.md) before applying the `20260625_0009_align_member_i…
  2. What this means The preflight query (from references/migration-file-schema-drift-pattern.md) joined public.members against auth.identities to find the…
  3. What this means oauth_subject = '000417...' matches the Apple subject in auth.identities.identity_data->>'sub'. The migration UPDATE will find a matchin…
  4. Why this matters for the durable fix The migration UPDATE has a WHERE clause:
  5. Why this matters for the durable fix WHERE m.oauth_provider = 'apple' AND ai.user_id = au.id AND ai.provider = 'apple' AND ai.identity_data->>'sub' = m.oauth_subject AND m.id <>…
  6. Why this matters for the durable fix This filter matches members.oauth_subject = auth.identities.identity_data->>'sub'. For row 2, members.oauth_subject = '' and `auth.ident…
  7. … 14 more sections in the full essay

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