diff --git a/db/update.go b/db/update.go index 6d9dc6b48..c14afa9bd 100644 --- a/db/update.go +++ b/db/update.go @@ -106,10 +106,10 @@ func updateCI(ctx api.ScrapeContext, result v1.ScrapeResult, ci, existing *model updates := make(map[string]interface{}) changes := make([]*models.ConfigChange, 0) - if ci.DeletedAt != existing.DeletedAt { + if lo.FromPtr(ci.DeletedAt).Unix() != lo.FromPtr(existing.DeletedAt).Unix() { updates["deleted_at"] = ci.DeletedAt updates["delete_reason"] = ci.DeleteReason - } else { + } else if existing.DeletedAt != nil { updates["deleted_at"] = gorm.Expr("NULL") updates["delete_reason"] = gorm.Expr("NULL") } @@ -163,7 +163,9 @@ func updateCI(ctx api.ScrapeContext, result v1.ScrapeResult, ci, existing *model updates["path"] = ci.Path } - if ci.CreatedAt != existing.CreatedAt { + if ci.CreatedAt.IsZero() && existing.CreatedAt.IsZero() { + updates["created_at"] = gorm.Expr("NOW()") + } else if ci.CreatedAt != existing.CreatedAt && !ci.CreatedAt.IsZero() { updates["created_at"] = ci.CreatedAt }