Skip to content

Commit

Permalink
chore: cleanup ghost component and config relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Jan 23, 2024
1 parent db88cd7 commit 14b5eca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/topology/component_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ var ComponentConfigRun = &job.Job{
}
run.History.IncrSuccess()
}

// Cleanup dead relationships
componentIDsWithConfigs := lo.Map(components, func(c pkg.Component, _ int) string { return c.ID.String() })
if err := db.Table("config_component_relationships").
Where("component_id NOT IN ?", componentIDsWithConfigs).
Update("deleted_at", duty.Now()).Error; err != nil {
return fmt.Errorf("error cleaning up old config_component_relationships: %w", err)
}
return nil
},
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/topology/component_relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ var ComponentRelationshipSync = &job.Job{
}
ctx.History.IncrSuccess()
}

// Cleanup dead relationships
componentIDsWithSelectors := lo.Map(components, func(c models.Component, _ int) string { return c.ID.String() })
if err := ctx.DB().Table("component_relationships").
Where("relationship_id NOT IN ?", componentIDsWithSelectors).
Update("deleted_at", duty.Now()).Error; err != nil {
return fmt.Errorf("error cleaning up dead component_relationships: %w", err)
}

return nil
},
}
Expand Down

0 comments on commit 14b5eca

Please sign in to comment.