Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add spec type filter to search plans (#16870)
boojack0e7912d689a5
diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.goindex f8225a8c0c..7270b72d84 100644--- a/backend/api/v1/plan_service.go+++ b/backend/api/v1/plan_service.go@@ -1046,16 +1046,6 @@ func (s *PlanService) buildPlanFindWithFilter(ctx context.Context, planFind *stovar getFilter func(expr celast.Expr) (string, error)var positionalArgs []any- parseToSQL := func(variable string, value any) (string, error) {- switch variable {- case "title":- positionalArgs = append(positionalArgs, value)- return fmt.Sprintf("plan.name = $%d", len(positionalArgs)), nil- default:- return "", connect.NewError(connect.CodeInvalidArgument, errors.Errorf("unsupported variable %q", variable))- }- }-getFilter = func(expr celast.Expr) (string, error) {switch expr.Kind() {case celast.CallKind:@@ -1091,8 +1081,26 @@ func (s *PlanService) buildPlanFindWithFilter(ctx context.Context, planFind *storeturn "issue.id IS NULL", nil}return "issue.id IS NOT NULL", nil+ case "title":+ positionalArgs = append(positionalArgs, value)+ return fmt.Sprintf("plan.name = $%d", len(positionalArgs)), nil+ case "spec_type":+ specType, ok := value.(string)+ if !ok {+ return "", connect.NewError(connect.CodeInvalidArgument, errors.Errorf("spec_type value must be a string"))+ }+ switch specType {+ case "create_database_config":+ return "EXISTS (SELECT 1 FROM jsonb_array_elements(plan.config->'specs') AS spec WHERE spec->>'createDatabaseConfig' IS NOT NULL)", nil+ case "change_database_config":+ return "EXISTS (SELECT 1 FROM jsonb_array_elements(plan.config->'specs') AS spec WHERE spec->>'changeDatabaseConfig' IS NOT NULL)", nil+ case "export_data_config":+ return "EXISTS (SELECT 1 FROM jsonb_array_elements(plan.config->'specs') AS spec WHERE spec->>'exportDataConfig' IS NOT NULL)", nil+ default:+ return "", connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid spec_type value: %s, must be one of: create_database_config, change_database_config, export_data_config", specType))+ }default:- return parseToSQL(variable, value)+ return "", connect.NewError(connect.CodeInvalidArgument, errors.Errorf("unsupported variable %q", variable))}case celoperators.GreaterEquals, celoperators.LessEquals:variable, rawValue := getVariableAndValueFromExpr(expr)diff --git a/backend/generated-go/v1/plan_service.pb.go b/backend/generated-go/v1/plan_service.pb.goindex d59b4142bc..f13af656ac 100644--- a/backend/generated-go/v1/plan_service.pb.go+++ b/backend/generated-go/v1/plan_service.pb.go@@ -448,12 +448,14 @@ type SearchPlansRequest struct {// - has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false".// - has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false".// - title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match.+ // - spec_type: the plan spec config type, support "==" operator, the value should be "create_database_config", "change_database_config", or "export_data_config".//// For example:// creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00"// has_pipeline == false && has_issue == true// title == "My Plan"// title.matches("database migration")+ // spec_type == "change_database_config"Filter string `protobuf:"bytes,4,opt,name=filter,proto3" json:"filter,omitempty"`unknownFields protoimpl.UnknownFieldssizeCache protoimpl.SizeCachediff --git a/frontend/src/store/modules/v1/plan.ts b/frontend/src/store/modules/v1/plan.tsindex ee676cd93e..bb9190fbde 100644--- a/frontend/src/store/modules/v1/plan.ts+++ b/frontend/src/store/modules/v1/plan.ts@@ -23,6 +23,7 @@ export interface PlanFind {createdTsBefore?: number;hasIssue?: boolean;hasPipeline?: boolean;+ specType?: string;}export const buildPlanFilter = (find: PlanFind): string => {@@ -49,6 +50,9 @@ export const buildPlanFilter = (find: PlanFind): string => {if (find.hasPipeline !== undefined) {filter.push(`has_pipeline == ${find.hasPipeline}`);}+ if (find.specType) {+ filter.push(`spec_type == "${find.specType}"`);+ }return filter.join(" && ");};diff --git a/frontend/src/types/proto-es/v1/plan_service_pb.d.ts b/frontend/src/types/proto-es/v1/plan_service_pb.d.tsindex 95a054fac1..bef9250bd8 100644--- a/frontend/src/types/proto-es/v1/plan_service_pb.d.ts+++ b/frontend/src/types/proto-es/v1/plan_service_pb.d.ts@@ -143,12 +143,14 @@ export declare type SearchPlansRequest = Message<"bytebase.v1.SearchPlansRequest* - has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false".* - has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false".* - title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match.+ * - spec_type: the plan spec config type, support "==" operator, the value should be "create_database_config", "change_database_config", or "export_data_config".** For example:* creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00"* has_pipeline == false && has_issue == true* title == "My Plan"* title.matches("database migration")+ * spec_type == "change_database_config"** @generated from field: string filter = 4;*/diff --git a/frontend/src/views/project/ProjectPlanDashboard.vue b/frontend/src/views/project/ProjectPlanDashboard.vueindex 41a58d52f3..21b4ce6988 100644--- a/frontend/src/views/project/ProjectPlanDashboard.vue+++ b/frontend/src/views/project/ProjectPlanDashboard.vue@@ -133,13 +133,17 @@ const planSearchParams = computed(() => {const mergedPlanFind = computed(() => {const defaultFind = enabledNewLayout.value- ? undefined+ ? {}: // Default find for legacy layout.{hasIssue: false,hasPipeline: false,};- return buildPlanFindBySearchParams(planSearchParams.value, defaultFind);+ return buildPlanFindBySearchParams(planSearchParams.value, {+ // Only show change database plans.+ specType: "change_database_config",+ ...defaultFind,+ });});const fetchPlanList = async ({diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yamlindex 14a842ea70..f3fbf0c78d 100644--- a/proto/gen/grpc-doc/openapi.yaml+++ b/proto/gen/grpc-doc/openapi.yaml@@ -13172,12 +13172,14 @@ components:- has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false".- has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false".- title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match.+ - spec_type: the plan spec config type, support "==" operator, the value should be "create_database_config", "change_database_config", or "export_data_config".For example:creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00"has_pipeline == false && has_issue == truetitle == "My Plan"title.matches("database migration")+ spec_type == "change_database_config"SearchPlansResponse:type: objectproperties:diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex 95840e6f71..ade375c6f1 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -7630,9 +7630,9 @@ When paginating, all other parameters provided to `ListPlans` must match the calWhen paginating, all other parameters provided to `SearchPlans` must match the call that provided the page token. || filter | [string](#string) | | Filter is used to filter plans returned in the list. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec-Supported filters: - creator: the plan creator full name in "users/{email or id}" format, support "==" operator. - create_time: issue create time in "2006-01-02T15:04:05Z07:00" format, support ">=" or "<=" operator. - has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false". - has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false". - title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match.+Supported filters: - creator: the plan creator full name in "users/{email or id}" format, support "==" operator. - create_time: issue create time in "2006-01-02T15:04:05Z07:00" format, support ">=" or "<=" operator. - has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false". - has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false". - title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match. - spec_type: the plan spec config type, support "==" operator, the value should be "create_database_config", "change_database_config", or "export_data_config".-For example: creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00" has_pipeline == false && has_issue == true title == "My Plan" title.matches("database migration") |+For example: creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00" has_pipeline == false && has_issue == true title == "My Plan" title.matches("database migration") spec_type == "change_database_config" |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex a71600577f..410253f7cd 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -21330,12 +21330,14 @@ Supported filters:- has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false".- has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false".- title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match.+- spec_type: the plan spec config type, support "==" operator, the value should be "create_database_config", "change_database_config", or "export_data_config".For example:creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00"has_pipeline == false && has_issue == truetitle == "My Plan"-title.matches("database migration") </p></td>+title.matches("database migration")+spec_type == "change_database_config" </p></td></tr></tbody>diff --git a/proto/v1/v1/plan_service.proto b/proto/v1/v1/plan_service.protoindex 38f5b762d5..18a01901f1 100644--- a/proto/v1/v1/plan_service.proto+++ b/proto/v1/v1/plan_service.proto@@ -169,12 +169,14 @@ message SearchPlansRequest {// - has_pipeline: the plan has pipeline or not, support "==" operator, the value should be "true" or "false".// - has_issue: the plan has issue or not, support "==" operator, the value should be "true" or "false".// - title: the plan title, support "==" operator for exact match and ".matches()" operator for case-insensitive substring match.+ // - spec_type: the plan spec config type, support "==" operator, the value should be "create_database_config", "change_database_config", or "export_data_config".//// For example:// creator == "users/[email protected]" && create_time >= "2025-01-02T15:04:05Z07:00"// has_pipeline == false && has_issue == true// title == "My Plan"// title.matches("database migration")+ // spec_type == "change_database_config"string filter = 4;}