Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: support issue search filter in backend (#8224)

ecmadao39af037958ac
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 02d47ef44f..fc6813682e 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -115,7 +115,7 @@ func (s *IssueService) ListIssues(ctx context.Context, request *v1pb.ListIssuesR
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
- var projectUID *int
+ var projectResourceID *string
if projectID != "-" {
project, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{
ResourceID: &projectID,
@@ -126,7 +126,7 @@ func (s *IssueService) ListIssues(ctx context.Context, request *v1pb.ListIssuesR
if project == nil {
return nil, status.Errorf(codes.NotFound, "project not found for id: %v", projectID)
}
- projectUID = &project.UID
+ projectResourceID = &project.ResourceID
}
limit := int(request.PageSize)
@@ -147,9 +147,9 @@ func (s *IssueService) ListIssues(ctx context.Context, request *v1pb.ListIssuesR
limitPlusOne := limit + 1
issueFind := &store.FindIssueMessage{
- ProjectUID: projectUID,
- Limit: &limitPlusOne,
- Offset: &offset,
+ ProjectResourceID: projectResourceID,
+ Limit: &limitPlusOne,
+ Offset: &offset,
}
filters, err := parseFilter(request.Filter)
@@ -247,18 +247,9 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
- var projectUID *int
+ var projectResourceID *string
if projectID != "-" {
- project, err := s.store.GetProjectV2(ctx, &store.FindProjectMessage{
- ResourceID: &projectID,
- })
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to get project, error: %v", err)
- }
- if project == nil {
- return nil, status.Errorf(codes.NotFound, "project not found for id: %v", projectID)
- }
- projectUID = &project.UID
+ projectResourceID = &projectID
}
limit := int(request.PageSize)
@@ -279,10 +270,10 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
limitPlusOne := limit + 1
issueFind := &store.FindIssueMessage{
- ProjectUID: projectUID,
- Query: &request.Query,
- Limit: &limitPlusOne,
- Offset: &offset,
+ ProjectResourceID: projectResourceID,
+ Query: &request.Query,
+ Limit: &limitPlusOne,
+ Offset: &offset,
}
filters, err := parseFilter(request.Filter)
@@ -352,6 +343,33 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
} else {
issueFind.CreatedTsBefore = &ts
}
+ case "type":
+ if spec.operator != comparatorTypeEqual {
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ }
+ if spec.value == "DDL" {
+ issueFind.TypeList = append(
+ issueFind.TypeList,
+ api.IssueDatabaseCreate,
+ api.IssueDatabaseSchemaUpdate,
+ api.IssueDatabaseSchemaUpdateGhost,
+ api.IssueDatabaseRestorePITR,
+ api.IssueDatabaseGeneral,
+ )
+ } else if spec.value == "DML" {
+ issueFind.TypeList = append(issueFind.TypeList, api.IssueDatabaseDataUpdate)
+ } else {
+ return nil, status.Errorf(codes.InvalidArgument, `unknown value "%s"`, spec.value)
+ }
+ case "instance":
+ if spec.operator != comparatorTypeEqual {
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ }
+ instanceResourceID, err := common.GetInstanceID(spec.value)
+ if err != nil {
+ return nil, status.Errorf(codes.InvalidArgument, `invalid instance resource id "%s": %v`, spec.value, err.Error())
+ }
+ issueFind.InstanceResourceID = &instanceResourceID
}
}
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index fd2d387b16..074608a9a2 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -208,7 +208,7 @@ func (s *ProjectService) DeleteProject(ctx context.Context, request *v1pb.Delete
// We don't close the issues because they might be open still.
} else {
// Return the open issue error first because that's more important than transferring out databases.
- openIssues, err := s.store.ListIssueV2(ctx, &store.FindIssueMessage{ProjectUID: &project.UID, StatusList: []api.IssueStatus{api.IssueOpen}})
+ openIssues, err := s.store.ListIssueV2(ctx, &store.FindIssueMessage{ProjectResourceID: &project.ResourceID, StatusList: []api.IssueStatus{api.IssueOpen}})
if err != nil {
return nil, err
}
diff --git a/backend/store/issue.go b/backend/store/issue.go
index f03c0c09d8..e7530ebb90 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -389,10 +389,11 @@ type UpdateIssueMessage struct {
// FindIssueMessage is the message to find issues.
type FindIssueMessage struct {
- UID *int
- ProjectUID *int
- PlanUID *int64
- PipelineID *int
+ UID *int
+ ProjectResourceID *string
+ InstanceResourceID *string
+ PlanUID *int64
+ PipelineID *int
// Find issues where principalID is either creator, assignee or subscriber.
PrincipalID *int
// To support pagination, we add into creator, assignee and subscriber.
@@ -404,6 +405,7 @@ type FindIssueMessage struct {
CreatedTsAfter *int64
StatusList []api.IssueStatus
+ TypeList []api.IssueType
// If specified, only find issues whose ID is smaller that SinceID.
SinceID *int
// If specified, then it will only fetch "Limit" most recently updated issues
@@ -684,9 +686,19 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
if v := find.PlanUID; v != nil {
where, args = append(where, fmt.Sprintf("issue.plan_id = $%d", len(args)+1)), append(args, *v)
}
- if v := find.ProjectUID; v != nil {
- where, args = append(where, fmt.Sprintf("issue.project_id = $%d", len(args)+1)), append(args, *v)
+
+ join := []string{}
+ if v := find.ProjectResourceID; v != nil {
+ join = append(join, "LEFT JOIN project ON project.id = issue.project_id")
+ where, args = append(where, fmt.Sprintf("project.resource_id = $%d", len(args)+1)), append(args, *v)
+ }
+ if v := find.InstanceResourceID; v != nil {
+ join = append(join, "LEFT JOIN pipeline ON pipeline.id = issue.pipeline_id")
+ join = append(join, "LEFT JOIN task ON task.pipeline_id = pipeline.id")
+ join = append(join, "LEFT JOIN instance ON instance.id = task.instance_id")
+ where, args = append(where, fmt.Sprintf("instance.resource_id = $%d", len(args)+1)), append(args, *v)
}
+
if v := find.PrincipalID; v != nil {
if find.CreatorID != nil || find.AssigneeID != nil || find.SubscriberID != nil {
return nil, &common.Error{Code: common.Invalid, Err: errors.New("principal_id cannot be used with creator_id, assignee_id, or subscriber_id")}
@@ -730,6 +742,14 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
}
where = append(where, fmt.Sprintf("issue.status IN (%s)", strings.Join(list, ", ")))
}
+ if len(find.TypeList) != 0 {
+ var list []string
+ for _, issueType := range find.TypeList {
+ list = append(list, fmt.Sprintf("$%d", len(args)+1))
+ args = append(args, issueType)
+ }
+ where = append(where, fmt.Sprintf("issue.type IN (%s)", strings.Join(list, ", ")))
+ }
limitOffsetClause := ""
if v := find.Limit; v != nil {
limitOffsetClause = fmt.Sprintf(" LIMIT %d", *v)
@@ -763,9 +783,10 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
issue.payload,
(SELECT ARRAY_AGG (issue_subscriber.subscriber_id) FROM issue_subscriber WHERE issue_subscriber.issue_id = issue.id) subscribers
FROM %s
+ %s
WHERE %s
%s
- %s`, from, strings.Join(where, " AND "), orderByClause, limitOffsetClause)
+ %s`, from, strings.Join(join, "\n"), strings.Join(where, " AND "), orderByClause, limitOffsetClause)
rows, err := tx.QueryContext(ctx, query, args...)
if err != nil {
diff --git a/frontend/src/components/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch.vue
index ec682df5ec..59e8166058 100644
--- a/frontend/src/components/AdvancedSearch.vue
+++ b/frontend/src/components/AdvancedSearch.vue
@@ -71,7 +71,6 @@ import { InstanceV1Name } from "@/components/v2";
import { useProjectV1ListByCurrentUser, useInstanceV1List } from "@/store";
import { Workflow } from "@/types/proto/v1/project_service";
import {
- isDev,
projectV1Name,
extractProjectResourceName,
extractInstanceResourceName,
@@ -165,37 +164,33 @@ const searchScopes = computed((): SearchScope[] => {
};
}),
},
+ {
+ id: "instance",
+ title: t("issue.advanced-search.scope.instance.title"),
+ description: t("issue.advanced-search.scope.instance.description"),
+ options: instanceList.value.map((ins) => {
+ return {
+ id: extractInstanceResourceName(ins.name),
+ label: h(InstanceV1Name, { instance: ins }),
+ };
+ }),
+ },
+ {
+ id: "type",
+ title: t("issue.advanced-search.scope.type.title"),
+ description: t("issue.advanced-search.scope.type.description"),
+ options: [
+ {
+ id: "DDL",
+ label: h("span", { innerHTML: "Data Definition Language" }),
+ },
+ {
+ id: "DML",
+ label: h("span", { innerHTML: "Data Manipulation Language" }),
+ },
+ ],
+ },
];
- if (isDev()) {
- scopes.push(
- {
- id: "instance",
- title: t("issue.advanced-search.scope.instance.title"),
- description: t("issue.advanced-search.scope.instance.description"),
- options: instanceList.value.map((ins) => {
- return {
- id: extractInstanceResourceName(ins.name),
- label: h(InstanceV1Name, { instance: ins }),
- };
- }),
- },
- {
- id: "type",
- title: t("issue.advanced-search.scope.type.title"),
- description: t("issue.advanced-search.scope.type.description"),
- options: [
- {
- id: "DDL",
- label: h("span", { innerHTML: "Data Definition Language" }),
- },
- {
- id: "DML",
- label: h("span", { innerHTML: "Data Manipulation Language" }),
- },
- ],
- }
- );
- }
return scopes;
});
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index e51d9af1a7..240dd9223a 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -77,6 +77,9 @@ export const buildIssueFilter = (find: IssueFilter): string => {
if (find.type) {
filter.push(`type = "${find.type}"`);
}
+ if (find.instance) {
+ filter.push(`instance = "${find.instance}"`);
+ }
return filter.join(" && ");
};