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: omit created_by field on upstream #575

Merged
merged 1 commit into from
Mar 5, 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
13 changes: 6 additions & 7 deletions upstream/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ func DeleteOnUpstream(ctx context.Context, req *PushData) error {
func InsertUpstreamMsg(ctx context.Context, req *PushData) error {
batchSize := 100
db := ctx.DB()

for _, c := range req.Topologies {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&c).Error; err != nil {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Omit("created_by").Create(&c).Error; err != nil {
return fmt.Errorf("error upserting topology: (id=%s): %w", c.ID, err)
}
}

for _, c := range req.Canaries {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&c).Error; err != nil {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Omit("created_by").Create(&c).Error; err != nil {
return fmt.Errorf("error upserting canaries: (id=%s): %w", c.ID, err)
}
}
Expand All @@ -142,7 +141,7 @@ func InsertUpstreamMsg(ctx context.Context, req *PushData) error {
}

for _, c := range req.ConfigScrapers {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&c).Error; err != nil {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Omit("created_by").Create(&c).Error; err != nil {
return fmt.Errorf("error upserting config scraper: (id=%s): %w", c.ID, err)
}
}
Expand All @@ -167,13 +166,13 @@ func InsertUpstreamMsg(ctx context.Context, req *PushData) error {
}

if len(req.ConfigChanges) > 0 {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).CreateInBatches(req.ConfigChanges, batchSize).Error; err != nil {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Omit("created_by").CreateInBatches(req.ConfigChanges, batchSize).Error; err != nil {
return fmt.Errorf("error upserting config_changes: %w", err)
}
}

if len(req.ConfigAnalysis) > 0 {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).CreateInBatches(req.ConfigAnalysis, batchSize).Error; err != nil {
if err := db.Clauses(clause.OnConflict{UpdateAll: true}).Omit("created_by").CreateInBatches(req.ConfigAnalysis, batchSize).Error; err != nil {
return fmt.Errorf("error upserting config_analysis: %w", err)
}
}
Expand Down Expand Up @@ -234,7 +233,7 @@ func saveIndividuallyWithRetries[T models.DBTable](ctx context.Context, items []
for {
var failed []T
for _, c := range items {
if err := ctx.DB().Clauses(clause.OnConflict{UpdateAll: true}).Create(&c).Error; err != nil {
if err := ctx.DB().Clauses(clause.OnConflict{UpdateAll: true}).Omit("created_by").Create(&c).Error; err != nil {
var pgError *pgconn.PgError
if errors.As(err, &pgError) {
if pgError.Code == pgerrcode.ForeignKeyViolation {
Expand Down
Loading