Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updating creation & deletion timestamps #719

Merged
merged 1 commit into from
Jul 9, 2024
Merged
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
9 changes: 6 additions & 3 deletions db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ 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) != lo.FromPtr(existing.DeletedAt) {
updates["deleted_at"] = ci.DeletedAt
updates["delete_reason"] = ci.DeleteReason
} else {
} else if existing.DeletedAt != nil && ci.DeletedAt == nil {
// item was previously deleted but is now being restored
updates["deleted_at"] = gorm.Expr("NULL")
updates["delete_reason"] = gorm.Expr("NULL")
}
Expand Down Expand Up @@ -163,7 +164,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
}

Expand Down
Loading