feat: collapse duplicate artists onto one canonical per Spotify id (chat#1889 row 9)
Row 9 of the canonical-artist trilogy on chat#1889. Mirrors the 20260707190000_repoint_funnel_duplicate_roster_artists pattern, keyed on the Spotify id extracted from profile_url instead of name-matching.
Dry-run measured on prod 2026-07-29 (read-only CTE of the exact migration logic):
| Metric | Count |
|---|---|
| Spotify ids with >1 linked artist | 79 |
| Collapsed by this migration | 77 |
| Skipped (ambiguous: >1 songs-graph owner) | 2 |
| Duplicate artist rows orphaned | 121 |
| Roster rows repointed/deduped | 140 |
| Accounts affected | 79 |
Canonical pick: songs-graph owner first (matches attachCanonicalArtistToAccount's notion of canonical), tie-break oldest social. Sanity anchor: for Ana Bárbara this picks f584e4f5 — the year-old row OneRPM's org accounts + sweetmantech@gmail.com already share — and orphans the two test-minted dupes.
Duplicates are orphaned, not deleted (FK blast radius; same call as the prior-art migration). Idempotent: a re-run finds no id with >1 linked artist. The 2 ambiguous ids intentionally need a human — I'll post them as a comment after merge.
Sequencing: independent of docs#278/api#793/chat#1901 (row 8) but row 10's deterministic pick assumes this has run. Apply via the usual flow; note the schema_migrations version-sync gotcha if applied manually through MCP.
🤖 Generated with Claude Code
Summary by cubic
Collapses duplicate artist accounts into one canonical per Spotify id to remove ambiguity in Spotify lookups and stop roster duplication. Targets chat#1889 (row 9).
- Migration
- Canonical per Spotify id: songs-graph owner first, else oldest social; skip ids with more than one owner.
- Repoint
account_artist_idsto the canonical, selecting at most one row per (account, canonical) to avoid unique collisions; delete leftover duplicate roster rows; move a Spotify social to the canonical if missing; remove duplicates’ Spotify links. Duplicates are orphaned, not deleted. Idempotent. - Dry-run on prod: 77 ids collapsed, 121 duplicate artists orphaned, 140 roster rows repointed across 79 accounts; 2 ids skipped as ambiguous.
Summary by CodeRabbit
- Bug Fixes
- Consolidated duplicate Spotify artist accounts into a single canonical artist per Spotify ID.
- Updated linked artist rosters to point to the canonical artist while avoiding key conflicts.
- Kept the most appropriate canonical account based on linked song ownership and recency.
- Ensured Spotify ID social links remain unique by removing duplicate Spotify associations without deleting duplicate artist accounts.