Skip to content

Commit

Permalink
feat: use unscoped delete for resource in manager (#2595)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Aug 3, 2023
1 parent a151be1 commit a966c04
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion manager/service/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *service) DestroyApplication(ctx context.Context, id uint) error {
return err
}

if err := s.db.WithContext(ctx).Delete(&models.Application{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Delete(&models.Application{}, id).Error; err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions manager/service/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *service) DestroyCluster(ctx context.Context, id uint) error {
return errors.New("seed peer cluster exists seed peer")
}

if err := tx.WithContext(ctx).Delete(&models.SeedPeerCluster{}, seedPeerCluster.ID).Error; err != nil {
if err := tx.WithContext(ctx).Unscoped().Delete(&models.SeedPeerCluster{}, seedPeerCluster.ID).Error; err != nil {
tx.Rollback()
return err
}
Expand All @@ -152,7 +152,7 @@ func (s *service) DestroyCluster(ctx context.Context, id uint) error {
return err
}

if err := tx.WithContext(ctx).Delete(&models.SchedulerCluster{}, id).Error; err != nil {
if err := tx.WithContext(ctx).Unscoped().Delete(&models.SchedulerCluster{}, id).Error; err != nil {
tx.Rollback()
return err
}
Expand Down
2 changes: 1 addition & 1 deletion manager/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *service) DestroyConfig(ctx context.Context, id uint) error {
return err
}

if err := s.db.WithContext(ctx).Unscoped().Delete(&models.Config{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Unscoped().Delete(&models.Config{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (s *service) DestroyJob(ctx context.Context, id uint) error {
return err
}

if err := s.db.WithContext(ctx).Delete(&models.Job{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Delete(&models.Job{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *service) DestroyOauth(ctx context.Context, id uint) error {
return err
}

if err := s.db.WithContext(ctx).Unscoped().Delete(&models.Oauth{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Unscoped().Delete(&models.Oauth{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/personal_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *service) DestroyPersonalAccessToken(ctx context.Context, id uint) error
return err
}

if err := s.db.WithContext(ctx).Delete(&models.PersonalAccessToken{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Delete(&models.PersonalAccessToken{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *service) DestroyScheduler(ctx context.Context, id uint) error {
return err
}

if err := s.db.WithContext(ctx).Unscoped().Delete(&models.Scheduler{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Unscoped().Delete(&models.Scheduler{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/scheduler_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *service) DestroySchedulerCluster(ctx context.Context, id uint) error {
return errors.New("scheduler cluster exists scheduler")
}

if err := s.db.WithContext(ctx).Delete(&models.SchedulerCluster{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Delete(&models.SchedulerCluster{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/seed_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *service) DestroySeedPeer(ctx context.Context, id uint) error {
return err
}

if err := s.db.WithContext(ctx).Unscoped().Delete(&models.SeedPeer{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Unscoped().Delete(&models.SeedPeer{}, id).Error; err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion manager/service/seed_peer_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *service) DestroySeedPeerCluster(ctx context.Context, id uint) error {
return errors.New("seedPeer cluster exists seedPeer")
}

if err := s.db.WithContext(ctx).Delete(&models.SeedPeerCluster{}, id).Error; err != nil {
if err := s.db.WithContext(ctx).Unscoped().Delete(&models.SeedPeerCluster{}, id).Error; err != nil {
return err
}

Expand Down

0 comments on commit a966c04

Please sign in to comment.