feat(migrations): repoint funnel duplicate roster artists to canonical twins (chat#1850 P1)

Merged
SW
5mo ago
+115-0

What

Data migration 20260707190000_repoint_funnel_duplicate_roster_artists.sql — the backfill half of chat#1850 P1. Already applied to the shared project (godremdqwajrwazhbrue) via the Supabase MCP on 2026-07-08 and verified; schema_migrations.version aligned to the file prefix. This PR lands the file so the repo history matches the applied state.

Scope (conservative; exact counts from the prod run)

A duplicate artist account qualifies only when ALL hold:

  1. referenced in account_artist_ids (on someone's roster);
  2. zero song_artists links;
  3. carries a Spotify artist social (the funnel PATCH signature);
  4. has exactly one same-accounts.name twin that HAS song_artists links (the unambiguous canonical);
  5. every referencing account also owns a catalog (the funnel claim signature).

What it did on prod: 18 candidate roster rows across 18 duplicate artist accounts → 14 rows repointed to their canonical twin. 4 rows intentionally left: 2 where the account already had the canonical linked (Dúo Dø, Pete Rango — dedupe skip) and 2 second-dupe rows for the same (account, canonical) pair (Mahakatha, Rusty Egan — account_artist_ids has no unique constraint on the pair, so only one row is repointed to avoid minting duplicates). 11 Spotify socials copied onto canonicals that had none (Barbet, Big L, Del Water Gap, Eliza Maturan, Elley Duhé, Kevin Gates, Mahakatha, Negghead, Rusty Egan, TAPZ GALLANTINO, Ulices Chaidez).

Excluded (documented): duplicates whose referencing account never claimed a catalog (28 of the 46 same-name twins) — their roster artist lights no surface without a catalog, and a later claim heals them through the api's claim-time attach. Duplicate accounts are NOT deleted (orphaned only; deletion is a follow-up).

Idempotent: verified post-apply — rerunning the candidate query selects 0 repointable rows; the social copy is NOT EXISTS-guarded; a raise-on-failure post-condition guards the repoint.

Verification (post-apply, prod)

  • Repro funnel account (sweetmantech+july720261741@gmail.com, account 0c88e3fa…): roster artist now resolves to canonical Del Water Gap 7647f901-a640-434c-b9c9-a18682435092 ✅
  • get_catalog_measurements_aggregate('4b934253-a20c-44c2-ada0-736551e15cb7', '7647f901-…') → 67 measured songs / 557,513,905 streams (was 0/0 with the duplicate) ✅

Links

Merge order

  1. docs → 2. database (this PR) → 3. api → 4. marketing. All PRs base main.

🤖 Generated with Claude Code