Skip to content

Commit

Permalink
fix: config_items_pkey constraint error (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored Sep 5, 2024
1 parent 6e78cb5 commit ccfae85
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ func saveResults(ctx api.ScrapeContext, results []v1.ScrapeResult) (v1.ScrapeSum
summary.AddChangeSummary(configType, cs)
}

if err := ctx.DB().CreateInBatches(newConfigs, configItemsBulkInsertSize).Error; err != nil {
// NOTE: On duplicate primary key do nothing
// because an incremental scraper might have already inserted the config item.
if err := ctx.DB().
Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "id"}}, DoNothing: true}).
CreateInBatches(newConfigs, configItemsBulkInsertSize).Error; err != nil {
return summary, fmt.Errorf("failed to create config items: %w", dutydb.ErrorDetails(err))
}
for _, config := range newConfigs {
Expand Down

0 comments on commit ccfae85

Please sign in to comment.