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: unsupported data type: &[] #2239

Merged
merged 1 commit into from
Oct 15, 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
24 changes: 14 additions & 10 deletions pkg/topology/component_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/query"
"github.com/google/uuid"
"github.com/lib/pq"
"github.com/pkg/errors"
"gorm.io/gorm"
"gorm.io/gorm/clause"
Expand All @@ -18,6 +19,12 @@ import (
"github.com/flanksource/canary-checker/pkg/utils"
)

// ComponentConfigsRelationship
type ComponentConfigsRelationship struct {
ComponentID string
ConfigIDs pq.StringArray `gorm:"type:[]text"`
}

var ComponentConfigRun = &job.Job{
Name: "ComponentConfigRun",
Schedule: "@every 2m",
Expand All @@ -35,24 +42,21 @@ var ComponentConfigRun = &job.Job{
return fmt.Errorf("error getting components: %w", err)
}

var existingRelationships []struct {
ComponentID uuid.UUID
ConfigIDs []uuid.UUID
}
var existingRelationships []ComponentConfigsRelationship
if err := db.Model(&models.ConfigComponentRelationship{}).
Select("component_id, ARRAY_AGG(config_id) AS config_ids").
Where("deleted_at IS NULL").
Group("component_id").Find(&existingRelationships).Error; err != nil {
return fmt.Errorf("error fetching existing config_component_relationships: %w", err)
}

existingConfigIDsByComponentID := make(map[uuid.UUID][]uuid.UUID)
existingConfigIDsByComponentID := make(map[string][]string)
for _, er := range existingRelationships {
existingConfigIDsByComponentID[er.ComponentID] = er.ConfigIDs
}

for _, component := range components {
if err := SyncComponentConfigRelationship(run.Context, component, existingConfigIDsByComponentID[component.ID]); err != nil {
if err := SyncComponentConfigRelationship(run.Context, component, existingConfigIDsByComponentID[component.ID.String()]); err != nil {
run.History.AddError(fmt.Sprintf("error persisting config relationships: %v", err))
continue
}
Expand Down Expand Up @@ -99,12 +103,12 @@ func PersistConfigComponentRelationship(db *gorm.DB, configID, componentID uuid.
}).Create(&relationship).Error
}

func SyncComponentConfigRelationship(ctx context.Context, component pkg.Component, existingConfigIDs []uuid.UUID) error {
func SyncComponentConfigRelationship(ctx context.Context, component pkg.Component, existingConfigIDs []string) error {
if len(component.Configs) == 0 {
return nil
}

var newConfigsIDs []uuid.UUID
var newConfigsIDs []string
var relationshipsToPersist []models.ConfigComponentRelationship

for _, config := range component.Configs {
Expand All @@ -114,9 +118,9 @@ func SyncComponentConfigRelationship(ctx context.Context, component pkg.Componen
}

for _, dbConfigID := range dbConfigIDs {
newConfigsIDs = append(newConfigsIDs, dbConfigID)
newConfigsIDs = append(newConfigsIDs, dbConfigID.String())

if collections.Contains(existingConfigIDs, dbConfigID) {
if collections.Contains(existingConfigIDs, dbConfigID.String()) {
continue
}

Expand Down
Loading