Skip to content

Conversation

@mbani01
Copy link
Contributor

@mbani01 mbani01 commented Jan 23, 2026

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 unified repositories table. 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

  • Deleted the GitReposRepository, GithubReposRepository, and GitlabReposRepository classes, 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]
  • Removed all usage and imports of these classes from 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

  • Updated code in integrationService.ts to interact only with the unified repositories table for all repository management operations, including upserts, deletions, and mapping logic. The code no longer references or syncs with git.repositories or other legacy tables. [1] [2] [3]

3. Database Schema Updates

  • Updated foreign key constraints in the database to reference the unified repositories table instead of the old git.repositories table, 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.repositories table and removes legacy per-platform repo logic.

  • Database: Update FKs to reference public.repositories (maintainersInternal.repoId, git.serviceExecutions.repoId) with ON DELETE CASCADE.
  • Backend services: Refactor integrationService to read/write only public.repositories; drop all interactions with git.repositories, githubRepos, gitlabRepos; generate repository IDs via uuid(); simplify deletion/mirroring validation and soft-deletes through unified APIs.
  • Nango worker: Remove legacy GitHub repo mapping calls; add/update repos directly via upsertRepository and soft-delete via unified helpers; keep Git integration remotes in sync.
  • Cronjob: Query/update archival status from public.repositories only.
  • Common services/DAL: Stop writing to 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.

Copy link
Contributor

Copilot AI left a 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, and git.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) to public.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
Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
const sourceIntegration = isGitHubPlatform ? IntegrationRepository.findById(sourceIntegrationId, txOptions) : null
const sourceIntegration = isGitHubPlatform
? await IntegrationRepository.findById(sourceIntegrationId, txOptions)
: null

Copilot uses AI. Check for mistakes.
import GitReposRepository from '../database/repositories/gitReposRepository'
import GithubReposRepository from '../database/repositories/githubReposRepository'
import IntegrationRepository from '../database/repositories/integrationRepository'
import IntegrationRepository from '../database/repositories/integrationRepository'
Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
import IntegrationRepository from '../database/repositories/integrationRepository'
import IntegrationRepository from '../database/repositories/integrationRepository'

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,8 @@
-- Drop the existing foreign key constraint to git.repositories
Copy link

Copilot AI Jan 23, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines 135 to 137
for (const repo of reposToBeRemoved) {
await removePlainGitHubRepoMapping(qx, redis, integrationId, repo)
await removePlainGitlabRepoMapping(qx, redis, integrationId, repo)
}
Copy link

Copilot AI Jan 23, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +9
ADD CONSTRAINT "maintainersInternal_repoId_fkey"
FOREIGN KEY ("repoId")
REFERENCES repositories(id)
ON DELETE CASCADE; No newline at end of file
Copy link

Copilot AI Jan 23, 2026

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.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,8 @@
-- Drop the existing foreign key constraint to git.repositories
ALTER TABLE git."serviceExecutions"
DROP CONSTRAINT "serviceExecutions_repoId_fkey";
Copy link

Copilot AI Jan 23, 2026

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).

Suggested change
DROP CONSTRAINT "serviceExecutions_repoId_fkey";
DROP CONSTRAINT IF EXISTS "serviceExecutions_repoId_fkey";

Copilot uses AI. Check for mistakes.
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@mbani01 mbani01 requested a review from ulemons January 23, 2026 13:43
Copy link

@cursor cursor bot left a 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.

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.

2 participants