diff --git a/db/update.go b/db/update.go index 076dcf2c..6d9dc6b4 100644 --- a/db/update.go +++ b/db/update.go @@ -109,6 +109,9 @@ func updateCI(ctx api.ScrapeContext, result v1.ScrapeResult, ci, existing *model if ci.DeletedAt != existing.DeletedAt { updates["deleted_at"] = ci.DeletedAt updates["delete_reason"] = ci.DeleteReason + } else { + updates["deleted_at"] = gorm.Expr("NULL") + updates["delete_reason"] = gorm.Expr("NULL") } changeResult, err := generateConfigChange(*ci, *existing) diff --git a/scrapers/run.go b/scrapers/run.go index 5a5e67ba..bb56847f 100644 --- a/scrapers/run.go +++ b/scrapers/run.go @@ -62,23 +62,5 @@ func UpdateStaleConfigItems(ctx api.ScrapeContext, results v1.ScrapeResults) err } } - // Any config item that was previously marked as deleted should be un-deleted - // if the item was re-discovered in this run. - if val := ctx.Value(contextKeyScrapeStart); val != nil { - if start, ok := val.(time.Time); ok { - query := `UPDATE config_items - SET deleted_at = NULL - WHERE deleted_at IS NOT NULL - AND deleted_at != updated_at - AND ((NOW() - last_scraped_time) <= INTERVAL '1 SECOND' * ?)` - tx := ctx.DutyContext().DB().Exec(query, time.Since(start).Seconds()) - if err := tx.Error; err != nil { - return fmt.Errorf("error un-deleting stale config items: %w", err) - } - - ctx.Logger.V(3).Infof("undeleted %d stale config items", tx.RowsAffected) - } - } - return nil }