Skip to content

feat(migrations): canonicalize socials twitter.com → x.com + merge twin rows#40

Merged
sweetmantech merged 1 commit into
mainfrom
fix/x-domain-dedupe-socials
Jul 6, 2026
Merged

feat(migrations): canonicalize socials twitter.com → x.com + merge twin rows#40
sweetmantech merged 1 commit into
mainfrom
fix/x-domain-dedupe-socials

Conversation

@sweetmantech

@sweetmantech sweetmantech commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Data-migration companion to api#755: rewrites all socials.profile_url twitter.com/* keys to the canonical x.com/* domain and merges rows where both spellings exist, so X scrape write-backs land on the rows artists are actually connected to.

Tracking issue: recoupable/chat#1851 (PR #2 of 2 required). Canonical-domain decision (x.com) recorded there 2026-07-06.

What it does

  1. Twin merge (403 pairs, measured 2026-07-06 prod): the x.com row is the keeper. Backfills any fresher scrape fields from the loser, repoints all 7 FK columns referencing socials.id (account_socials.social_id, social_posts.social_id, post_comments.social_id, social_fans.artist_social_id, social_fans.fan_social_id, fan_segments.fan_social_id, agent_status.social_id) with delete-guards on each table's unique/logical key, then deletes the loser.
  2. In-place rename (23,622 twinless rows): twitter.com/<handle>x.com/<handle>.
  3. Post-condition: raises if any twitter.com/* key survives, so a partial run cannot commit silently.

Verification (dry-run against prod inside a rolled-back transaction, 2026-07-06)

Check Result
All statements execute, no constraint violations
twitter.com/* rows remaining 0
x.com/* rows after 76,072 (= 52,450 existing + 23,622 renamed — exact)
Issue's Done-when fixture: the 3 artist-connected rows from chat#1851 all 3 repointed to x.com/* keepers
x.com/disclosure keeper carries the fresh scrape 483,103 followers (was orphaned; connected row showed 0)
DB state after rollback untouched (24,025 / 52,450 — confirmed)

Merge sequencing

api#755 merges first (stops new twitter.com keys being written), then this migration cleans up existing rows. Running this first would also work but re-drift until the api change deploys.

🤖 Generated with Claude Code


Summary by cubic

Canonicalizes socials from twitter.com to x.com by merging duplicate rows and repointing foreign keys so X scraper write-backs attach to artist-connected records. Twinless twitter rows are renamed in place, and the migration fails if any twitter.com keys remain.

Written for commit 981c173. Summary will update on new commits.

Review in cubic

…win rows

Companion to recoupable/api#755 (normalizeProfileUrl canonicalization).
Merges 403 twitter/x twin pairs (repointing 7 FK columns with unique-
constraint guards) and renames 23,622 twinless twitter.com keys in place.
Post-condition check raises if any twitter.com key survives.

Tracking: recoupable/chat#1851 (PR #2 of 2 required).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@sweetmantech, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72c35d03-6603-4e20-854b-26bd97cd7a3c

📥 Commits

Reviewing files that changed from the base of the PR and between bdffa77 and 981c173.

📒 Files selected for processing (1)
  • supabase/migrations/20260706180000_canonicalize_twitter_to_x_socials.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/x-domain-dedupe-socials

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Jul 6, 2026

Copy link
Copy Markdown

Updates to Preview Branch (fix/x-domain-dedupe-socials) ↗︎

Deployments Status Updated
Database Mon, 06 Jul 2026 17:00:20 UTC
Services Mon, 06 Jul 2026 17:00:20 UTC
APIs Mon, 06 Jul 2026 17:00:20 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Mon, 06 Jul 2026 17:00:27 UTC
Migrations Mon, 06 Jul 2026 17:00:31 UTC
Seeding Mon, 06 Jul 2026 17:00:31 UTC
Edge Functions Mon, 06 Jul 2026 17:00:32 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="supabase/migrations/20260706180000_canonicalize_twitter_to_x_socials.sql">

<violation number="1" location="supabase/migrations/20260706180000_canonicalize_twitter_to_x_socials.sql:135">
P2: Twinless twitter→x renames will still bump `socials.updated_at`, so rows can look freshly scraped even though only `profile_url` changed. `updated_at = updated_at` does not bypass the table’s `set_updated_at` trigger; preserving timestamps needs trigger bypass/restore or an explicit post-update restoration step.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

-- 2. Twinless twitter rows: rename the key in place.
UPDATE public.socials
SET profile_url = 'x.com/' || substring(profile_url FROM 13),
updated_at = updated_at -- key rename only; not a data refresh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Twinless twitter→x renames will still bump socials.updated_at, so rows can look freshly scraped even though only profile_url changed. updated_at = updated_at does not bypass the table’s set_updated_at trigger; preserving timestamps needs trigger bypass/restore or an explicit post-update restoration step.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At supabase/migrations/20260706180000_canonicalize_twitter_to_x_socials.sql, line 135:

<comment>Twinless twitter→x renames will still bump `socials.updated_at`, so rows can look freshly scraped even though only `profile_url` changed. `updated_at = updated_at` does not bypass the table’s `set_updated_at` trigger; preserving timestamps needs trigger bypass/restore or an explicit post-update restoration step.</comment>

<file context>
@@ -0,0 +1,147 @@
+-- 2. Twinless twitter rows: rename the key in place.
+UPDATE public.socials
+SET profile_url = 'x.com/' || substring(profile_url FROM 13),
+    updated_at  = updated_at  -- key rename only; not a data refresh
+WHERE profile_url LIKE 'twitter.com/%';
+
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant