Skip to content

fix: merge case-duplicate github repos and enforce unique lower(url) [CM-1344]#4383

Merged
mbani01 merged 5 commits into
mainfrom
fix/duplicated_repos
Jul 22, 2026
Merged

fix: merge case-duplicate github repos and enforce unique lower(url) [CM-1344]#4383
mbani01 merged 5 commits into
mainfrom
fix/duplicated_repos

Conversation

@mbani01

@mbani01 mbani01 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces a migration to clean up duplicate GitHub repositories in the repos table, which arose due to case sensitivity issues in URLs. The migration consolidates duplicate entries by keeping a single canonical (lowercase) row per repository, re-points associated data, and enforces case-insensitive uniqueness for GitHub URLs going forward.

Duplicate GitHub repository consolidation:

  • Identifies groups of duplicate repositories (differing only by URL case) and selects a keeper per group, preferring the all-lowercase variant when present.
  • Re-points package_repos and repo_docker to the keeper repository, ensuring only one link per package/group combination, and removes redundant links.
  • Deletes derived data (repo_scorecard_checks, security_contacts, repo_activity_snapshot) associated with loser repositories, as these will be regenerated as needed.
  • Removes the loser repository rows from the repos table and normalizes the surviving repository URL to lowercase if needed.
  • Adds a partial unique index to enforce case-insensitive uniqueness of GitHub repository URLs, preventing future duplicates.

…ueness

Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
@mbani01 mbani01 self-assigned this Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 11:41
@cursor

cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Large-scale destructive data migration on core repos/package_repos with Tinybird CDC implications; incorrect keeper or link logic could break package–repo provenance or duplicate security contacts until sweeps recover.

Overview
Adds two Flyway migrations to clean up ~40k case-variant duplicate GitHub repos rows left after CM-1305 re-pointed package links but did not remove losers.

The first migration runs atomically: picks a keeper per LOWER(url) (prefer all-lowercase, else lowest id), dedupes package_repos using the same ranking as bestRepoLink, re-points loser links via insert+delete (not UPDATE) for Tinybird CDC, updates repo_docker and lowercases denormalized packages.repository_url, drops derived loser data, deletes loser repos, then lowercases surviving mixed-case GitHub URLs.

The second migration adds a partial unique index repos_github_lower_url_uq on LOWER(url) for host = 'github' CONCURRENTLY, split out so the merge stays transactional and workers stay writable; index build failure also verifies no duplicates remain.

Reviewed by Cursor Bugbot for commit ac4dc81. Bugbot is set up for automated code reviews on this repo. Configure here.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Consolidates case-duplicate GitHub repositories and prevents recurrence.

Changes:

  • Re-points dependent records and removes duplicate repositories.
  • Normalizes surviving GitHub URLs.
  • Adds case-insensitive uniqueness enforcement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
Copilot AI review requested due to automatic review settings July 22, 2026 11:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread backend/src/osspckgs/migrations/V1784718694__repos_github_lower_url_guard.sql Outdated
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
Copilot AI review requested due to automatic review settings July 22, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

backend/src/osspckgs/migrations/V1784718693__merge_case_duplicate_github_repos.sql:101

  • url is the Tinybird repos sorting key (services/libs/tinybird/datasources/repos.datasource:74). This update therefore inserts a new lowercase key but cannot replace the previously ingested mixed-case key; FINAL keeps both, and joins by repo ID can duplicate downstream results. Include a Tinybird cleanup/rebuild or tombstone path for the old URLs.
UPDATE repos r
SET url = LOWER(r.url), updated_at = NOW()
WHERE r.host = 'github'
  AND r.url <> LOWER(r.url);

Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
Copilot AI review requested due to automatic review settings July 22, 2026 12:28

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eff5795. Configure here.

FROM repos r
WHERE r.host = 'github'
AND p.repository_url = r.url
AND p.repository_url <> LOWER(p.repository_url);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Case-sensitive package URL join

Medium Severity

The migration lowercases packages.repository_url only when it equals a GitHub repos.url byte-for-byte. GitHub URLs are case-insensitive, so a package can refer to the same repo as a row in repos while using a casing variant that was never inserted. Those rows skip the update and keep a mixed-case repository_url after repos is normalized, breaking the intended alignment with canonical lowercase URLs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit eff5795. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

backend/src/osspckgs/migrations/V1784718693__merge_case_duplicate_github_repos.sql:112

  • This key-mutating update is not CDC-safe for Tinybird: repos.datasource uses url as its ReplacingMergeTree sorting key (services/libs/tinybird/datasources/repos.datasource:72-75), so the lowercase event cannot replace the old mixed-case key under FINAL. The migration mentions a packageRepos rebuild, but the deployment must also rebuild repos (and account for the deleted derived rows), otherwise the duplicates remain visible in Tinybird.
UPDATE repos r
SET url = LOWER(r.url), updated_at = NOW()
WHERE r.host = 'github'
  AND r.url <> LOWER(r.url);

Copilot AI review requested due to automatic review settings July 22, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +109 to +112
UPDATE repos r
SET url = LOWER(r.url), updated_at = NOW()
WHERE r.host = 'github'
AND r.url <> LOWER(r.url);
@mbani01
mbani01 merged commit 84deb7e into main Jul 22, 2026
14 checks passed
@mbani01
mbani01 deleted the fix/duplicated_repos branch July 22, 2026 14:30
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.

3 participants