Skip to content

Commit

Permalink
fix: conflict clause
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed May 1, 2024
1 parent 8422166 commit a3c872c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
13 changes: 1 addition & 12 deletions pkg/db/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,7 @@ func CreateCheck(ctx context.Context, canary pkg.Canary, check *pkg.Check) error
func PersistCanaryModel(ctx context.Context, model pkg.Canary) (*pkg.Canary, error) {
db := ctx.DB()
err := db.Clauses(
clause.OnConflict{
Columns: []clause.Column{{Name: "agent_id"}, {Name: "name"}, {Name: "namespace"}, {Name: "source"}},
TargetWhere: clause.Where{
Exprs: []clause.Expression{
clause.Or(
clause.Eq{Column: "deleted_at", Value: gorm.Expr("NULL")},
clause.Not(clause.Eq{Column: "agent_id", Value: uuid.Nil.String()}),
),
},
},
DoUpdates: clause.AssignmentColumns([]string{"labels", "spec"}),
},
models.Canary{}.ConflictClause(),
clause.Returning{},
).Create(&model).Error

Expand Down
13 changes: 1 addition & 12 deletions pkg/db/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,7 @@ func PersistV1Topology(ctx context.Context, t *v1.Topology) (pkg.Topology, bool,

func PersistTopology(ctx context.Context, model *pkg.Topology) (bool, error) {
tx := ctx.DB().
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "agent_id"}, {Name: "name"}, {Name: "namespace"}},
TargetWhere: clause.Where{
Exprs: []clause.Expression{
clause.Or(
clause.Eq{Column: "deleted_at", Value: gorm.Expr("NULL")},
clause.Not(clause.Eq{Column: "agent_id", Value: uuid.Nil.String()}),
),
},
},
DoUpdates: clause.AssignmentColumns([]string{"labels", "spec"}),
}).
Clauses(models.Topology{}.OnConflictClause()).
Create(model)
if tx.Error != nil {
return false, tx.Error
Expand Down

0 comments on commit a3c872c

Please sign in to comment.