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: expose unspecified SQL type in approvals (#20423)
rebelice27098e40e326
diff --git a/backend/runner/approval/runner_test.go b/backend/runner/approval/runner_test.goindex 7f887b58e9..24cf6a56b0 100644--- a/backend/runner/approval/runner_test.go+++ b/backend/runner/approval/runner_test.go@@ -4,6 +4,7 @@ import ("testing""github.com/stretchr/testify/require"+ "google.golang.org/genproto/googleapis/type/expr""github.com/bytebase/bytebase/backend/common"storepb "github.com/bytebase/bytebase/backend/generated-go/store"@@ -177,6 +178,25 @@ func TestCalculateRiskLevelFromCELVars(t *testing.T) {}}+func TestApprovalTemplateMatchesUnspecifiedStatementSQLType(t *testing.T) {+ a := require.New(t)++ approvalTemplate, err := getApprovalTemplate(&storepb.WorkspaceApprovalSetting{+ Rules: []*storepb.WorkspaceApprovalSetting_Rule{+ {+ Source: storepb.WorkspaceApprovalSetting_Rule_CHANGE_DATABASE,+ Condition: &expr.Expr{Expression: `statement.sql_type == "STATEMENT_TYPE_UNSPECIFIED"`},+ Template: &storepb.ApprovalTemplate{Title: "Unspecified SQL type rule"},+ },+ },+ }, storepb.WorkspaceApprovalSetting_Rule_CHANGE_DATABASE, expandCELVars(map[string]any{+ common.CELAttributeResourceProjectID: "project",+ }, []storepb.StatementType{storepb.StatementType_STATEMENT_TYPE_UNSPECIFIED}, nil))+ a.NoError(err)+ a.NotNil(approvalTemplate)+ a.Equal("Unspecified SQL type rule", approvalTemplate.Title)+}+func TestBuildStatementSummaryResultMapUsesSheetSHA256(t *testing.T) {results := []*storepb.PlanCheckRunResult_Result{{diff --git a/frontend/src/plugins/cel/types/values.test.ts b/frontend/src/plugins/cel/types/values.test.tsnew file mode 100644index 0000000000..6d909ccb45--- /dev/null+++ b/frontend/src/plugins/cel/types/values.test.ts@@ -0,0 +1,9 @@+import { describe, expect, it } from "vitest";++import { SQLTypeList } from "./values";++describe("SQLTypeList", () => {+ it("puts the unspecified statement type last for approval CEL rules", () => {+ expect(SQLTypeList.ALL.at(-1)).toBe("STATEMENT_TYPE_UNSPECIFIED");+ });+});diff --git a/frontend/src/plugins/cel/types/values.ts b/frontend/src/plugins/cel/types/values.tsindex 87c629cde4..eadbc118f5 100644--- a/frontend/src/plugins/cel/types/values.ts+++ b/frontend/src/plugins/cel/types/values.ts@@ -1,5 +1,9 @@import { StatementType } from "@/types/proto-es/v1/common_pb";+const OTHER_STATEMENT_TYPES = [+ StatementType.STATEMENT_TYPE_UNSPECIFIED,+] as const;+// DDL statement typesconst DDL_STATEMENT_TYPES = [StatementType.CREATE_DATABASE,@@ -55,6 +59,12 @@ const getStatementTypeName = (type: StatementType): string => {// Export lists with string names for backward compatibility with existing codeexport const SQLTypeList = {+ OTHER: OTHER_STATEMENT_TYPES.map(getStatementTypeName),DDL: DDL_STATEMENT_TYPES.map(getStatementTypeName),DML: DML_STATEMENT_TYPES.map(getStatementTypeName),+ ALL: [+ ...DDL_STATEMENT_TYPES,+ ...DML_STATEMENT_TYPES,+ ...OTHER_STATEMENT_TYPES,+ ].map(getStatementTypeName),} as const;diff --git a/frontend/src/react/components/CustomApproval/utils.ts b/frontend/src/react/components/CustomApproval/utils.tsindex 0fc2e0c973..1a786ba4bb 100644--- a/frontend/src/react/components/CustomApproval/utils.ts+++ b/frontend/src/react/components/CustomApproval/utils.ts@@ -205,7 +205,7 @@ const getSQLTypeOptions = (source: WorkspaceApprovalSetting_Rule_Source) => {};switch (source) {case WorkspaceApprovalSetting_Rule_Source.CHANGE_DATABASE:- return mapOptions([...SQLTypeList.DDL, ...SQLTypeList.DML]);+ return mapOptions(SQLTypeList.ALL);}// unsupported sourcereturn [];