Skip to content

Commit

Permalink
chore: add audit plan model for delete project
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanghc committed Nov 20, 2024
1 parent 42c3ebf commit 8245ec3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sqle/model/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/actiontech/sqle/sqle/errors"
Expand Down Expand Up @@ -531,3 +532,22 @@ func (s *Storage) UpdateAuditPlanLastCollectionTime(auditPlanID uint, collection
}
return nil
}

func (s *Storage) GetAuditPlansByProjectId(projectID string) ([]*InstanceAuditPlan, error) {
instanceAuditPlan := []*InstanceAuditPlan{}
err := s.db.Model(InstanceAuditPlan{}).Where("project_id = ?", projectID).Find(&instanceAuditPlan).Error
return instanceAuditPlan, err
}

func (s Storage) DeleteAuditPlansInProject(projectID string) error {
instAuditPlans, err := s.GetAuditPlansByProjectId(projectID)
if err != nil {
return err
}
for _, instAP := range instAuditPlans {
if err := s.DeleteInstanceAuditPlan(strconv.FormatUint(uint64(instAP.ID), 10)); err != nil {
return err
}
}
return nil
}

0 comments on commit 8245ec3

Please sign in to comment.