diff --git a/core/provider/service.go b/core/provider/service.go index 7687d74b6..81bdf0556 100644 --- a/core/provider/service.go +++ b/core/provider/service.go @@ -390,6 +390,19 @@ func (s *Service) getResources(ctx context.Context, p *domain.Provider) ([]*doma isFound := false for _, r := range res { if er.URN == r.URN { + existingMetadata := er.Details + if existingMetadata != nil { + if r.Details != nil { + for key, value := range existingMetadata { + if _, ok := r.Details[key]; !ok { + r.Details[key] = value + } + } + } else { + r.Details = existingMetadata + } + } + resources = append(resources, r) isFound = true break diff --git a/internal/store/postgres/resource_repository.go b/internal/store/postgres/resource_repository.go index bb47380e0..d7dda1c6f 100644 --- a/internal/store/postgres/resource_repository.go +++ b/internal/store/postgres/resource_repository.go @@ -131,7 +131,7 @@ func (r *ResourceRepository) BulkUpsert(resources []*domain.Resource) error { {Name: "type"}, {Name: "urn"}, }, - DoUpdates: clause.AssignmentColumns([]string{"name", "updated_at", "is_deleted"}), + DoUpdates: clause.AssignmentColumns([]string{"name", "details", "updated_at", "is_deleted"}), } if err := r.db.Clauses(upsertClause).Create(models).Error; err != nil { return err diff --git a/internal/store/postgres/resource_repository_test.go b/internal/store/postgres/resource_repository_test.go index 6755efa0e..a855a01ef 100644 --- a/internal/store/postgres/resource_repository_test.go +++ b/internal/store/postgres/resource_repository_test.go @@ -213,7 +213,7 @@ func (s *ResourceRepositoryTestSuite) TestBulkUpsert() { }, } - expectedQuery := regexp.QuoteMeta(`INSERT INTO "resources" ("provider_type","provider_urn","type","urn","name","details","labels","created_at","updated_at","deleted_at","is_deleted") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11),($12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22) ON CONFLICT ("provider_type","provider_urn","type","urn") DO UPDATE SET "name"="excluded"."name","updated_at"="excluded"."updated_at","is_deleted"="excluded"."is_deleted" RETURNING "id"`) + expectedQuery := regexp.QuoteMeta(`INSERT INTO "resources" ("provider_type","provider_urn","type","urn","name","details","labels","created_at","updated_at","deleted_at","is_deleted") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11),($12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22) ON CONFLICT ("provider_type","provider_urn","type","urn") DO UPDATE SET "name"="excluded"."name","details"="excluded"."details","updated_at"="excluded"."updated_at","is_deleted"="excluded"."is_deleted" RETURNING "id"`) expectedArgs := []driver.Value{} for _, r := range resources { expectedArgs = append(expectedArgs,