diff --git a/backend/src/services/collectionService.ts b/backend/src/services/collectionService.ts index 74bfd1d84e..302d63ba94 100644 --- a/backend/src/services/collectionService.ts +++ b/backend/src/services/collectionService.ts @@ -455,7 +455,9 @@ export class CollectionService extends LoggerBase { } } - await this.syncRepositoryGroupsWithDb(qx, insightsProjectId, project.repositoryGroups) + if (project.repositoryGroups !== undefined) { + await this.syncRepositoryGroupsWithDb(qx, insightsProjectId, project.repositoryGroups) + } const txSvc = new CollectionService({ ...this.options, diff --git a/backend/src/services/segmentService.ts b/backend/src/services/segmentService.ts index aa32044f5a..e53267a676 100644 --- a/backend/src/services/segmentService.ts +++ b/backend/src/services/segmentService.ts @@ -69,6 +69,15 @@ export default class SegmentService extends LoggerBase { }) } + if (isSegmentSubproject(segment) && data.slug && data.slug !== segment.slug) { + const collectionService = new CollectionService({ ...this.options, transaction }) + const projects = await collectionService.findInsightsProjectsBySegmentId(segment.id) + if (projects.length > 0) { + const normalizedSlug = data.slug.replace(/^nonlf_/, '') + await collectionService.updateInsightsProject(projects[0].id, { slug: normalizedSlug }) + } + } + await SequelizeRepository.commitTransaction(transaction) return await this.findById(id) diff --git a/services/libs/data-access-layer/src/collections/index.ts b/services/libs/data-access-layer/src/collections/index.ts index d53649bfac..7921faaa17 100644 --- a/services/libs/data-access-layer/src/collections/index.ts +++ b/services/libs/data-access-layer/src/collections/index.ts @@ -332,6 +332,23 @@ export async function updateInsightsProject( await syncRepositoriesEnabledStatus(qx, id, enabledUrls) } + // When slug changes, ON UPDATE CASCADE propagates the new slug to securityInsights* tables + // but does not touch their updatedAt — update it explicitly so Tinybird picks up the change + if (project.slug) { + await qx.result( + `UPDATE "securityInsightsEvaluationSuites" SET "updatedAt" = NOW() WHERE "insightsProjectSlug" = $(slug)`, + { slug: project.slug }, + ) + await qx.result( + `UPDATE "securityInsightsEvaluations" SET "updatedAt" = NOW() WHERE "insightsProjectSlug" = $(slug)`, + { slug: project.slug }, + ) + await qx.result( + `UPDATE "securityInsightsEvaluationAssessments" SET "updatedAt" = NOW() WHERE "insightsProjectSlug" = $(slug)`, + { slug: project.slug }, + ) + } + return updated as IInsightsProject }