Skip to content

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

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.go
index 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 *sto
var 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 *sto
return "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.go
index 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.UnknownFields
sizeCache protoimpl.SizeCache
diff --git a/frontend/src/store/modules/v1/plan.ts b/frontend/src/store/modules/v1/plan.ts
index 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.ts
index 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.vue
index 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.yaml
index 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 == true
title == "My Plan"
title.matches("database migration")
+ spec_type == "change_database_config"
SearchPlansResponse:
type: object
properties:
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 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 cal
When 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 &#34;users/{email or id}&#34; format, support &#34;==&#34; operator. - create_time: issue create time in &#34;2006-01-02T15:04:05Z07:00&#34; format, support &#34;&gt;=&#34; or &#34;&lt;=&#34; operator. - has_pipeline: the plan has pipeline or not, support &#34;==&#34; operator, the value should be &#34;true&#34; or &#34;false&#34;. - has_issue: the plan has issue or not, support &#34;==&#34; operator, the value should be &#34;true&#34; or &#34;false&#34;. - title: the plan title, support &#34;==&#34; operator for exact match and &#34;.matches()&#34; operator for case-insensitive substring match.
+Supported filters: - creator: the plan creator full name in &#34;users/{email or id}&#34; format, support &#34;==&#34; operator. - create_time: issue create time in &#34;2006-01-02T15:04:05Z07:00&#34; format, support &#34;&gt;=&#34; or &#34;&lt;=&#34; operator. - has_pipeline: the plan has pipeline or not, support &#34;==&#34; operator, the value should be &#34;true&#34; or &#34;false&#34;. - has_issue: the plan has issue or not, support &#34;==&#34; operator, the value should be &#34;true&#34; or &#34;false&#34;. - title: the plan title, support &#34;==&#34; operator for exact match and &#34;.matches()&#34; operator for case-insensitive substring match. - spec_type: the plan spec config type, support &#34;==&#34; operator, the value should be &#34;create_database_config&#34;, &#34;change_database_config&#34;, or &#34;export_data_config&#34;.
-For example: creator == &#34;users/[email protected]&#34; &amp;&amp; create_time &gt;= &#34;2025-01-02T15:04:05Z07:00&#34; has_pipeline == false &amp;&amp; has_issue == true title == &#34;My Plan&#34; title.matches(&#34;database migration&#34;) |
+For example: creator == &#34;users/[email protected]&#34; &amp;&amp; create_time &gt;= &#34;2025-01-02T15:04:05Z07:00&#34; has_pipeline == false &amp;&amp; has_issue == true title == &#34;My Plan&#34; title.matches(&#34;database migration&#34;) spec_type == &#34;change_database_config&#34; |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 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 &#34;==&#34; operator, the value should be &#34;true&#34; or &#34;false&#34;.
- has_issue: the plan has issue or not, support &#34;==&#34; operator, the value should be &#34;true&#34; or &#34;false&#34;.
- title: the plan title, support &#34;==&#34; operator for exact match and &#34;.matches()&#34; operator for case-insensitive substring match.
+- spec_type: the plan spec config type, support &#34;==&#34; operator, the value should be &#34;create_database_config&#34;, &#34;change_database_config&#34;, or &#34;export_data_config&#34;.
For example:
creator == &#34;users/[email protected]&#34; &amp;&amp; create_time &gt;= &#34;2025-01-02T15:04:05Z07:00&#34;
has_pipeline == false &amp;&amp; has_issue == true
title == &#34;My Plan&#34;
-title.matches(&#34;database migration&#34;) </p></td>
+title.matches(&#34;database migration&#34;)
+spec_type == &#34;change_database_config&#34; </p></td>
</tr>
</tbody>
diff --git a/proto/v1/v1/plan_service.proto b/proto/v1/v1/plan_service.proto
index 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;
}