Make Spotify onboarding and roster attachment atomic

Merged
SI
2mo ago
+462-0

Existing Spotify artists could miss organization roster attachment, and a failed new-artist attachment could leave partial records. This adds service-role-only transactions for exact Spotify resolution and legacy name-only creation, with membership checks and atomic roster relationships. Spotify lookup accepts the stored, scheme-stripped URL format and preserves case-sensitive provider identity. Conflicting mappings fail without reassignment.

Tracks recoupable/app#2166. Apply the ordered migrations through 20261008040000_recheck_spotify_social_owner.sql before deploying https://github.com/recoupable/api/pull/969. No existing records are cleaned up, no global identity constraints are added, and no rights are assigned. Legacy writers outside these functions remain in recoupable/app#2119.

Validation: 18 tests passed against disposable PostgreSQL 17, including 16 concurrent calls, new/existing identity, namesakes, non-admin revocation, role privileges, lookup failure, persisted normalized social IDs, and Spotify/name-only attachment rollback. The minimal fixture loads the repository's actual social-normalization trigger migrations. GitHub Actions now runs this suite for every PR. This remains narrower than a full Supabase migration replay.

Hosted preflight found that FOR SHARE needs UPDATE on at least one membership column. The final migration grants only UPDATE(updated_at) to service_role, preserving the row lock without granting changes to membership identity columns. The fixture now mirrors the observed preview grants and proves identity mutation remains denied. No manual dashboard grant was made.

Hosted preview service-role checks passed for new/reused identity, retries, name-only creation, ambiguity rejection, and denied access, with all synthetic writes rolled back and zero fixture records remaining. Full authenticated UI → API → persisted roster verification remains pending. The latest migration also rejects ownership acquired by a concurrent legacy writer; its local two-session test verifies rollback and retry. The production OAuth migration at 010000 is preserved; onboarding starts at 020000. Merged and deployment verified; authenticated production roster acceptance remains pending. See tests/README.md for deployment order and validation boundaries.

Release evidence: https://github.com/recoupable/app/issues/2166#issuecomment-6050403984 (hosted preview checkpoint). Final production commit/deployment and verification boundaries are recorded in the latest release checkpoint on recoupable/app#2166 and #2167.