Skip to content

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

chore: issue advanced search support search by database (#8389)

ecmadao7d251f8dbf28
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 5c114f2d1d..e964d8813e 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -284,7 +284,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
switch spec.key {
case "principal":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "principal" filter`)
}
user, err := s.getUserByIdentifier(ctx, spec.value)
if err != nil {
@@ -293,7 +293,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
issueFind.PrincipalID = &user.ID
case "creator":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "creator" filter`)
}
user, err := s.getUserByIdentifier(ctx, spec.value)
if err != nil {
@@ -302,7 +302,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
issueFind.CreatorID = &user.ID
case "assignee":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "assignee" filter`)
}
user, err := s.getUserByIdentifier(ctx, spec.value)
if err != nil {
@@ -311,7 +311,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
issueFind.AssigneeID = &user.ID
case "subscriber":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "subscriber" filter`)
}
user, err := s.getUserByIdentifier(ctx, spec.value)
if err != nil {
@@ -320,7 +320,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
issueFind.SubscriberID = &user.ID
case "status":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "status" filter`)
}
for _, raw := range strings.Split(spec.value, " | ") {
newStatus, err := convertToAPIIssueStatus(v1pb.IssueStatus(v1pb.IssueStatus_value[raw]))
@@ -335,7 +335,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
}
t, err := time.Parse(time.RFC3339, spec.value)
if err != nil {
- return nil, status.Errorf(codes.InvalidArgument, "failed to parse create_time_before %s, err: %v", spec.value, err)
+ return nil, status.Errorf(codes.InvalidArgument, "failed to parse create_time %s, err: %v", spec.value, err)
}
ts := t.Unix()
if spec.operator == comparatorTypeGreaterEqual {
@@ -345,7 +345,7 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
}
case "type":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "type" filter`)
}
switch spec.value {
case "DDL":
@@ -364,13 +364,29 @@ func (s *IssueService) SearchIssues(ctx context.Context, request *v1pb.SearchIss
}
case "instance":
if spec.operator != comparatorTypeEqual {
- return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "level" filter`)
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "instance" 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
+ case "database":
+ if spec.operator != comparatorTypeEqual {
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "database" filter`)
+ }
+ instanceID, databaseName, err := common.GetInstanceDatabaseID(spec.value)
+ if err != nil {
+ return nil, status.Errorf(codes.InvalidArgument, err.Error())
+ }
+ database, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{
+ InstanceID: &instanceID,
+ DatabaseName: &databaseName,
+ })
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, err.Error())
+ }
+ issueFind.DatabaseUID = &database.UID
}
}
diff --git a/frontend/src/components/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch.vue
index 59e8166058..f3416bcbfa 100644
--- a/frontend/src/components/AdvancedSearch.vue
+++ b/frontend/src/components/AdvancedSearch.vue
@@ -67,16 +67,25 @@ import { NInput } from "naive-ui";
import { reactive, computed, h, VNode, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
import GitIcon from "@/components/GitIcon.vue";
-import { InstanceV1Name } from "@/components/v2";
-import { useProjectV1ListByCurrentUser, useInstanceV1List } from "@/store";
+import {
+ InstanceV1Name,
+ InstanceV1EngineIcon,
+ DatabaseV1Name,
+} from "@/components/v2";
+import {
+ useProjectV1ListByCurrentUser,
+ useInstanceV1List,
+ useSearchDatabaseV1List,
+} from "@/store";
import { Workflow } from "@/types/proto/v1/project_service";
import {
projectV1Name,
+ environmentV1Name,
extractProjectResourceName,
extractInstanceResourceName,
} from "@/utils";
-type SearchScopeId = "project" | "instance" | "type";
+type SearchScopeId = "project" | "instance" | "database" | "type";
export interface SearchParams {
query: string;
@@ -142,6 +151,9 @@ const inputRef = ref<InstanceType<typeof NInput>>();
const { projectList } = useProjectV1ListByCurrentUser();
const { instanceList } = useInstanceV1List(false /* !showDeleted */);
+const { databaseList } = useSearchDatabaseV1List({
+ parent: "instances/-",
+});
const searchScopes = computed((): SearchScope[] => {
// TODO(ed): The scope options should have relevance.
@@ -160,7 +172,7 @@ const searchScopes = computed((): SearchScope[] => {
}
return {
id: extractProjectResourceName(proj.name),
- label: h("div", { class: "flex gap-x-2" }, children),
+ label: h("div", { class: "flex items-center gap-x-2" }, children),
};
}),
},
@@ -171,7 +183,31 @@ const searchScopes = computed((): SearchScope[] => {
options: instanceList.value.map((ins) => {
return {
id: extractInstanceResourceName(ins.name),
- label: h(InstanceV1Name, { instance: ins }),
+ label: h("div", { class: "flex items-center gap-x-1" }, [
+ h(InstanceV1Name, { instance: ins }),
+ h("span", {
+ innerHTML: `(${environmentV1Name(ins.environmentEntity)})`,
+ }),
+ ]),
+ };
+ }),
+ },
+ {
+ id: "database",
+ title: t("issue.advanced-search.scope.database.title"),
+ description: t("issue.advanced-search.scope.database.description"),
+ options: databaseList.value.map((db) => {
+ return {
+ id: `${db.databaseName}-${db.uid}`,
+ label: h("div", { class: "flex items-center gap-x-1" }, [
+ h(InstanceV1EngineIcon, { instance: db.instanceEntity }),
+ h(DatabaseV1Name, { database: db, link: false }),
+ h("span", {
+ innerHTML: `(${environmentV1Name(
+ db.effectiveEnvironmentEntity
+ )})`,
+ }),
+ ]),
};
}),
},
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 0fa7203c01..5d02597bea 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -831,6 +831,10 @@
"title": "Instance",
"description": "Include only issues related with the instance"
},
+ "database": {
+ "title": "Database",
+ "description": "Include only issues related with the database"
+ },
"type": {
"title": "Change Type",
"description": "The database change type for issues"
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index dc56f39352..aea4bc9218 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -830,6 +830,10 @@
"title": "Instancia",
"description": "Incluir solo problemas relacionados con la instancia"
},
+ "database": {
+ "title": "Base de datos",
+ "description": "Incluir sólo cuestiones relacionadas con la base de datos"
+ },
"type": {
"title": "Tipo de cambio",
"description": "El tipo de cambio de base de datos para problemas"
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 939c563da2..400bcbf344 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -828,6 +828,10 @@
"title": "实例",
"description": "仅搜索与某个实例关联的工单"
},
+ "database": {
+ "title": "数据库",
+ "description": "仅搜索与某个数据库关联的工单"
+ },
"type": {
"title": "变更类型",
"description": "根据数据库变更类型搜索"
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index d02f0fae9f..bb248d6224 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -64,6 +64,9 @@ export const buildIssueFilter = (find: IssueFilter): string => {
if (find.instance) {
filter.push(`instance = "${find.instance}"`);
}
+ if (find.database) {
+ filter.push(`database = "${find.database}"`);
+ }
return filter.join(" && ");
};
diff --git a/frontend/src/types/proto/v1/issue_service.ts b/frontend/src/types/proto/v1/issue_service.ts
index 2e1c08d11e..2ac58023c6 100644
--- a/frontend/src/types/proto/v1/issue_service.ts
+++ b/frontend/src/types/proto/v1/issue_service.ts
@@ -165,6 +165,8 @@ export interface SearchIssuesRequest {
* - create_time >= "2022-01-01T12:00:00.000Z"
* - instance, example:
* - instance = "instancs/{resource id}"
+ * - database, example:
+ * - database = "instancs/{instance resource id}/databases/{database name}"
* - type, only support "DDL" or "DML", example:
* - type = "DDL"
*/
diff --git a/frontend/src/types/v1/issue/issue.ts b/frontend/src/types/v1/issue/issue.ts
index f100f3325f..6ed11c67e8 100644
--- a/frontend/src/types/v1/issue/issue.ts
+++ b/frontend/src/types/v1/issue/issue.ts
@@ -79,6 +79,7 @@ export const unknownIssue = (): ComposedIssue => {
export interface IssueFilter {
project: string;
instance?: string;
+ database?: string;
query: string;
principal?: string;
creator?: string;
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index db202a9349..df0608b464 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -108,7 +108,12 @@ import AdvancedSearch, { SearchParams } from "@/components/AdvancedSearch.vue";
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
import { UserSelect, SearchBox, TabFilterItem } from "@/components/v2";
-import { useCurrentUserV1, useProjectV1Store, useUserStore } from "@/store";
+import {
+ useCurrentUserV1,
+ useProjectV1Store,
+ useDatabaseV1Store,
+ useUserStore,
+} from "@/store";
import {
projectNamePrefix,
userNamePrefix,
@@ -139,6 +144,7 @@ const route = useRoute();
const { t } = useI18n();
const currentUserV1 = useCurrentUserV1();
const projectV1Store = useProjectV1Store();
+const databaseV1Store = useDatabaseV1Store();
const statusList = computed((): string[] =>
route.query.status ? (route.query.status as string).split(",") : []
@@ -348,11 +354,20 @@ const issueFilter = computed((): IssueFilter => {
const projectScope = scopes.find((s) => s.id === "project");
const instanceScope = scopes.find((s) => s.id === "instance");
const typeScope = scopes.find((s) => s.id === "type");
+ const databaseScope = scopes.find((s) => s.id === "database");
let instance = "";
if (instanceScope) {
instance = `${instanceNamePrefix}${instanceScope.value}`;
}
+ let database = "";
+ if (databaseScope) {
+ const uid = databaseScope.value.split("-").slice(-1)[0];
+ const db = databaseV1Store.getDatabaseByUID(uid);
+ if (db.uid !== `${UNKNOWN_ID}`) {
+ database = db.name;
+ }
+ }
let principal = "";
if (selectedUser.value) {
principal = `${userNamePrefix}${selectedUser.value.email}`;
@@ -361,6 +376,7 @@ const issueFilter = computed((): IssueFilter => {
query,
principal,
instance,
+ database,
project: `${projectNamePrefix}${projectScope?.value ?? "-"}`,
createdTsAfter: selectedTimeRange.value
? selectedTimeRange.value[0]
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 3737c65cc4..3502f0e354 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -5522,7 +5522,7 @@ When paginating, all other parameters provided to `ListIssues` must match the ca
When paginating, all other parameters provided to `SearchIssues` must match the call that provided the page token. |
| query | [string](#string) | | Query is the query statement. |
-| filter | [string](#string) | | Filter is used to filter issues returned in the list, follow the [ebnf](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) syntax. Supported field in filter: - principal, example: - principal = &#34;users/{email}&#34; - creator, example: - creator = &#34;users/{email}&#34; - assignee, example: - assignee = &#34;users/{email}&#34; - subscriber, example: - subscriber = &#34;users/{email}&#34; - status, example: - status = &#34;OPEN&#34; - status = &#34;DONE&#34; | &#34;CANCELED&#34; - create_time, example: - create_time &lt;= &#34;2022-01-01T12:00:00.000Z&#34; - create_time &gt;= &#34;2022-01-01T12:00:00.000Z&#34; - instance, example: - instance = &#34;instancs/{resource id}&#34; - type, only support &#34;DDL&#34; or &#34;DML&#34;, example: - type = &#34;DDL&#34; |
+| filter | [string](#string) | | Filter is used to filter issues returned in the list, follow the [ebnf](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) syntax. Supported field in filter: - principal, example: - principal = &#34;users/{email}&#34; - creator, example: - creator = &#34;users/{email}&#34; - assignee, example: - assignee = &#34;users/{email}&#34; - subscriber, example: - subscriber = &#34;users/{email}&#34; - status, example: - status = &#34;OPEN&#34; - status = &#34;DONE&#34; | &#34;CANCELED&#34; - create_time, example: - create_time &lt;= &#34;2022-01-01T12:00:00.000Z&#34; - create_time &gt;= &#34;2022-01-01T12:00:00.000Z&#34; - instance, example: - instance = &#34;instancs/{resource id}&#34; - database, example: - database = &#34;instancs/{instance resource id}/databases/{database name}&#34; - type, only support &#34;DDL&#34; or &#34;DML&#34;, example: - type = &#34;DDL&#34; |
diff --git a/proto/generated-go/v1/issue_service.pb.go b/proto/generated-go/v1/issue_service.pb.go
index b1ca65e87d..c41e2f3e1a 100644
--- a/proto/generated-go/v1/issue_service.pb.go
+++ b/proto/generated-go/v1/issue_service.pb.go
@@ -705,6 +705,9 @@ type SearchIssuesRequest struct {
// - instance, example:
// - instance = "instancs/{resource id}"
//
+ // - database, example:
+ // - database = "instancs/{instance resource id}/databases/{database name}"
+ //
// - type, only support "DDL" or "DML", example:
// - type = "DDL"
Filter string `protobuf:"bytes,5,opt,name=filter,proto3" json:"filter,omitempty"`
diff --git a/proto/v1/issue_service.proto b/proto/v1/issue_service.proto
index f061aecd16..8b31fd76ec 100644
--- a/proto/v1/issue_service.proto
+++ b/proto/v1/issue_service.proto
@@ -190,6 +190,8 @@ message SearchIssuesRequest {
// - create_time >= "2022-01-01T12:00:00.000Z"
// - instance, example:
// - instance = "instancs/{resource id}"
+ // - database, example:
+ // - database = "instancs/{instance resource id}/databases/{database name}"
// - type, only support "DDL" or "DML", example:
// - type = "DDL"
string filter = 5;