-
Notifications
You must be signed in to change notification settings - Fork 727
refactor: stop writing to old repositories tables[CM-905] #3776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR removes legacy per-platform repository table logic (git.repositories, githubRepos, gitlabRepos) and consolidates repository management around the unified public.repositories table, including updating related foreign key constraints.
Changes:
- Removed legacy repository mapping/sync functions and repository classes tied to
githubRepos,gitlabRepos, andgit.repositories. - Updated GitHub Nango workflows/activities and backend integration logic to stop writing to legacy tables and to use
public.repositories. - Added DB migrations to repoint FK constraints (e.g.,
git.serviceExecutions,maintainersInternal) topublic.repositories.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| services/libs/data-access-layer/src/repositories/index.ts | Removes helper that queried legacy git.repositories IDs by URL. |
| services/libs/data-access-layer/src/integrations/index.ts | Deletes legacy GitHub repo mapping + git V2 sync logic; updates deletion to target public.repositories. |
| services/libs/common_services/src/services/integration.service.ts | Stops unmapping GitHub legacy table; relies on unified repository deletion. |
| services/apps/nango_worker/src/workflows/syncGithubIntegration.ts | Removes legacy mapping steps; keeps only unified repository operations. |
| services/apps/nango_worker/src/activities/nangoActivities.ts | Removes legacy GitHub repo mapping calls; updates Git integration update and repository upsert flow. |
| services/apps/nango_worker/src/activities.ts | Stops exporting removed legacy activity. |
| backend/src/services/integrationService.ts | Removes legacy repo-table writes/reads; updates unified repository mapping flow. |
| backend/src/database/migrations/V1769097489__changeGitServiceExecutionRefreneceToRepositories.sql | Updates git.serviceExecutions.repoId FK to reference public.repositories. |
| backend/src/database/migrations/V1769092368__changeMaintainersRepoReferenceToRepositories.sql | Updates maintainersInternal.repoId FK to reference repositories. |
| backend/src/database/migrations/U1769097489__changeGitServiceExecutionRefreneceToRepositories.sql | Added undo migration file (currently empty). |
| backend/src/database/migrations/U1769092368__changeMaintainersRepoReferenceToRepositories.sql | Added undo migration file (currently empty). |
| backend/src/database/repositories/{gitReposRepository,githubReposRepository,gitlabReposRepository}.ts | Deletes legacy repository repository classes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const isGitHubPlatform = [PlatformType.GITHUB, PlatformType.GITHUB_NANGO].includes( | ||
| sourcePlatform, | ||
| ) | ||
| const sourceIntegration = isGitHubPlatform ? IntegrationRepository.findById(sourceIntegrationId, txOptions) : null |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sourceIntegration is assigned the Promise returned by IntegrationRepository.findById(...), but later treated like a resolved integration object (sourceIntegration?.settings?.orgs). This makes the forkedFrom map never populate and can lead to incorrect forkedFrom values. Await the lookup (or include it in the existing async flow) before accessing .settings.
| const sourceIntegration = isGitHubPlatform ? IntegrationRepository.findById(sourceIntegrationId, txOptions) : null | |
| const sourceIntegration = isGitHubPlatform | |
| ? await IntegrationRepository.findById(sourceIntegrationId, txOptions) | |
| : null |
| import GitReposRepository from '../database/repositories/gitReposRepository' | ||
| import GithubReposRepository from '../database/repositories/githubReposRepository' | ||
| import IntegrationRepository from '../database/repositories/integrationRepository' | ||
| import IntegrationRepository from '../database/repositories/integrationRepository' |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import line has trailing whitespace, which can cause lint/prettier failures in repos that enforce no-trailing-spaces.
| import IntegrationRepository from '../database/repositories/integrationRepository' | |
| import IntegrationRepository from '../database/repositories/integrationRepository' |
| @@ -0,0 +1,8 @@ | |||
| -- Drop the existing foreign key constraint to git.repositories | |||
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration filename contains a typo: "Refrenece". Renaming to "Reference" will improve clarity and make it easier to find/search for this migration later.
| for (const repo of reposToBeRemoved) { | ||
| await removePlainGitHubRepoMapping(qx, redis, integrationId, repo) | ||
| await removePlainGitlabRepoMapping(qx, redis, integrationId, repo) | ||
| } |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop is unmapping GitHub Nango repos, but it now calls removePlainGitlabRepoMapping(...) (which is no longer GitLab-specific). Renaming the DAL function (and updating this call site) would make the intent clearer and prevent accidental platform-specific assumptions later.
| ADD CONSTRAINT "maintainersInternal_repoId_fkey" | ||
| FOREIGN KEY ("repoId") | ||
| REFERENCES repositories(id) | ||
| ON DELETE CASCADE; No newline at end of file |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This migration uses REFERENCES repositories(id) without a schema qualifier, while other migrations in this repo typically qualify (e.g., REFERENCES git.repositories(id) in V1762938833__migrateMaintainersRepoReferenceToGitRepositories.sql and REFERENCES public.repositories(id) in V1766669430__createGitRepositoryProcessingTable.sql). Prefer public.repositories(id) here for consistency and to avoid relying on search_path.
| @@ -0,0 +1,8 @@ | |||
| -- Drop the existing foreign key constraint to git.repositories | |||
| ALTER TABLE git."serviceExecutions" | |||
| DROP CONSTRAINT "serviceExecutions_repoId_fkey"; | |||
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DROP CONSTRAINT is executed without IF EXISTS, which can make the migration fail if the constraint name differs across environments or has already been removed. Consider using DROP CONSTRAINT IF EXISTS ... (as done in V1769092368__changeMaintainersRepoReferenceToRepositories.sql).
| DROP CONSTRAINT "serviceExecutions_repoId_fkey"; | |
| DROP CONSTRAINT IF EXISTS "serviceExecutions_repoId_fkey"; |
There was a problem hiding this comment.
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.
…g git integration duplicates
This pull request removes legacy repository management logic and updates database references to streamline how repositories are tracked and managed across the codebase. The changes focus on eliminating the use of old per-platform repository tables (
git.repositories,githubRepos,gitlabRepos) and their associated repository classes, and instead rely on the unifiedrepositoriestable. Additionally, related foreign key constraints in the database are updated to reference the new structure.Key changes include:
1. Removal of Legacy Repository Management Logic
GitReposRepository,GithubReposRepository, andGitlabReposRepositoryclasses, which previously handled repository CRUD operations for their respective tables. All related logic for soft-deleting, upserting, and mapping repositories in these legacy tables has been removed from the codebase. [1] [2] [3]integrationService.ts, including all code paths that performed soft deletes or mapping updates in the legacy tables. [1] [2] [3] [4] [5] [6] [7]2. Migration to Unified Repository Table
integrationService.tsto interact only with the unifiedrepositoriestable for all repository management operations, including upserts, deletions, and mapping logic. The code no longer references or syncs withgit.repositoriesor other legacy tables. [1] [2] [3]3. Database Schema Updates
repositoriestable instead of the oldgit.repositoriestable, including cascading deletes for related tables (maintainersInternal,git.serviceExecutions). [1] [2]These changes simplify repository management, reduce technical debt, and ensure all repository-related data is managed consistently in a single place.
Note
Consolidates repository management on the unified
public.repositoriestable and removes legacy per-platform repo logic.public.repositories(maintainersInternal.repoId,git.serviceExecutions.repoId) withON DELETE CASCADE.integrationServiceto read/write onlypublic.repositories; drop all interactions withgit.repositories,githubRepos,gitlabRepos; generate repository IDs viauuid(); simplify deletion/mirroring validation and soft-deletes through unified APIs.upsertRepositoryand soft-delete via unified helpers; keep Git integration remotes in sync.public.repositoriesonly.segmentRepositories; update insights syncing to derive from unified repositories; remove obsolete repo-mapping utilities.Written by Cursor Bugbot for commit 6ba2fc5. This will update automatically on new commits. Configure here.