Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/src/services/collectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions backend/src/services/segmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions services/libs/data-access-layer/src/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading