Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-bk-bcs/master'
Browse files Browse the repository at this point in the history
* github-bk-bcs/master:
  fix: delete app with hook reference relationship (#2706)
  • Loading branch information
wenxinlee2015 committed Oct 25, 2023
2 parents 66b6357 + 6896952 commit 0cb98f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bcs-services/bcs-bscp/cmd/data-service/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ func (s *Service) deleteAppRelatedResources(grpcKit *kit.Kit, req *pbds.DeleteAp
return err
}

// delete released hook
if err := s.dao.ReleasedHook().DeleteByAppIDWithTx(grpcKit, tx, req.Id, req.BizId); err != nil {
logs.Errorf("delete released hooks failed, err: %v, rid: %s", err, grpcKit.Rid)
return err
}

return nil
}

Expand Down
15 changes: 15 additions & 0 deletions bcs-services/bcs-bscp/pkg/dal/dao/released_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type ReleasedHook interface {
CreateWithTx(kit *kit.Kit, tx *gen.QueryTx, releasedHook *table.ReleasedHook) (uint32, error)
// ListAll list all released hooks in biz
ListAll(kit *kit.Kit, bizID uint32) ([]*table.ReleasedHook, error)
// DeleteByAppIDWithTx deletes the released hook by app id with transaction.
DeleteByAppIDWithTx(kit *kit.Kit, tx *gen.QueryTx, appID, bizID uint32) error
// DeleteByUniqueKeyWithTx deletes the released hook by unique key with transaction.
DeleteByUniqueKeyWithTx(kit *kit.Kit, tx *gen.QueryTx, rh *table.ReleasedHook) error
// DeleteByHookIDAndReleaseIDWithTx deletes the released hook by hook id and release id with transaction.
Expand Down Expand Up @@ -227,6 +229,19 @@ func (dao *releasedHookDao) ListAll(kit *kit.Kit, bizID uint32) ([]*table.Releas
return rhs, nil
}

// DeleteByAppIDWithTx deletes the released hook by app id with transaction.
func (dao *releasedHookDao) DeleteByAppIDWithTx(kit *kit.Kit, tx *gen.QueryTx, appID, bizID uint32) error {
if bizID == 0 {
return errf.New(errf.InvalidParameter, "bizID is 0")
}
if appID == 0 {
return errf.New(errf.InvalidParameter, "appID is 0")
}
m := tx.ReleasedHook
_, err := m.WithContext(kit.Ctx).Where(m.BizID.Eq(bizID), m.AppID.Eq(appID)).Delete()
return err
}

// DeleteByUniqueKeyWithTx deletes the released hook by unique key with transaction.
func (dao *releasedHookDao) DeleteByUniqueKeyWithTx(kit *kit.Kit, tx *gen.QueryTx, rh *table.ReleasedHook) error {
if rh == nil {
Expand Down

0 comments on commit 0cb98f7

Please sign in to comment.