Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: external approval store list (#6631)
p0nyb270c7a211f0
diff --git a/backend/runner/apprun/runner.go b/backend/runner/apprun/runner.goindex 16685a0397..a54d7e607b 100644--- a/backend/runner/apprun/runner.go+++ b/backend/runner/apprun/runner.go@@ -103,7 +103,10 @@ func (r *Runner) Run(ctx context.Context, wg *sync.WaitGroup) {r.scheduleApproval(ctx, issue, stages, &value)}- externalApprovalList, err := r.store.FindExternalApprovalV2(ctx)+ externalApprovalType := api.ExternalApprovalTypeFeishu+ externalApprovalList, err := r.store.ListExternalApprovalV2(ctx, &store.ListExternalApprovalMessage{+ Type: &externalApprovalType,+ })if err != nil {log.Error("failed to find external approval list", zap.Error(err))returndiff --git a/backend/store/external_approval.go b/backend/store/external_approval.goindex 468a028d3e..aeaee1eb07 100644--- a/backend/store/external_approval.go+++ b/backend/store/external_approval.go@@ -43,10 +43,11 @@ type UpdateExternalApprovalMessage struct {Payload *string}-// listExternalApprovalMessage is the message for listing external approvals.-type listExternalApprovalMessage struct {- // issueUID is the unique identifier of the issue.- issueUID *int+// ListExternalApprovalMessage is the message for listing external approvals.+type ListExternalApprovalMessage struct {+ // IssueUID is the unique identifier of the issue.+ IssueUID *int+ Type *api.ExternalApprovalType}// CreateExternalApprovalV2 creates an ExternalApproval.@@ -89,14 +90,14 @@ func (s *Store) CreateExternalApprovalV2(ctx context.Context, create *ExternalApreturn &externalApproval, nil}-// FindExternalApprovalV2 finds a list of ExternalApproval by find and whose RowStatus == NORMAL.-func (s *Store) FindExternalApprovalV2(ctx context.Context) ([]*ExternalApprovalMessage, error) {+// ListExternalApprovalV2 finds a list of ExternalApproval by find and whose RowStatus == NORMAL.+func (s *Store) ListExternalApprovalV2(ctx context.Context, find *ListExternalApprovalMessage) ([]*ExternalApprovalMessage, error) {tx, err := s.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})if err != nil {return nil, errors.Wrapf(err, "failed to begin transaction")}- externalApprovals, err := s.findExternalApprovalImplV2(ctx, tx, &listExternalApprovalMessage{})+ externalApprovals, err := s.findExternalApprovalImplV2(ctx, tx, find)if err != nil {return nil, errors.Wrapf(err, "failed to find external approval")}@@ -115,7 +116,7 @@ func (s *Store) GetExternalApprovalByIssueIDV2(ctx context.Context, issueID int)return nil, errors.Wrapf(err, "failed to begin transaction")}- externalApprovals, err := s.findExternalApprovalImplV2(ctx, tx, &listExternalApprovalMessage{issueUID: &issueID})+ externalApprovals, err := s.findExternalApprovalImplV2(ctx, tx, &ListExternalApprovalMessage{IssueUID: &issueID})if err != nil {return nil, errors.Wrapf(err, "failed to find external approval")}@@ -168,12 +169,15 @@ func (s *Store) UpdateExternalApprovalV2(ctx context.Context, update *UpdateExtereturn &externalApproval, nil}-func (*Store) findExternalApprovalImplV2(ctx context.Context, tx *Tx, find *listExternalApprovalMessage) ([]*ExternalApprovalMessage, error) {+func (*Store) findExternalApprovalImplV2(ctx context.Context, tx *Tx, find *ListExternalApprovalMessage) ([]*ExternalApprovalMessage, error) {where, args := []string{"TRUE"}, []any{}where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, api.Normal)- if v := find.issueUID; v != nil {+ if v := find.IssueUID; v != nil {where, args = append(where, fmt.Sprintf("issue_id = $%d", len(args)+1)), append(args, *v)}+ if v := find.Type; v != nil {+ where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, *v)+ }rows, err := tx.QueryContext(ctx, `SELECT