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: optimize sql review (#11076)
ecmadaoadaaeecf2660
diff --git a/frontend/src/bbkit/BBTextField.vue b/frontend/src/bbkit/BBTextField.vueindex 64641750f3..d6b73da110 100644--- a/frontend/src/bbkit/BBTextField.vue+++ b/frontend/src/bbkit/BBTextField.vue@@ -12,6 +12,7 @@:autosize="autosize":status="state.hasError ? 'error' : undefined"@blur="onBlur"+ @focus="$emit('on-focus')"@update:value="onInput($event)"@keypress.enter="onPressEnter"@input="$emit('input', $event)"@@ -57,6 +58,7 @@ const emit = defineEmits<{(event: "end-editing", value: string): void;(event: "update:value", value: string): void;(event: "input", value: string): void;+ (event: "on-focus"): void;}>();const inputField = ref();diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vueindex f8628911b6..277ffc97b6 100644--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue@@ -49,11 +49,14 @@<span class="border-r border-control-border ml-1"></span></template><template- v-if="row.checkResult.sqlReviewReport && getActiveRule(row.checkResult.title as RuleType)"+ v-if="+ row.checkResult.sqlReviewReport &&+ getActiveRule(row.checkResult.title)+ "><spanclass="ml-1 normal-link"- @click="setActiveRule(row.checkResult.title as RuleType)"+ @click="setActiveRule(row.checkResult.title)">{{ $t("sql-review.rule-detail") }}</span><span class="border-r border-control-border ml-1"></span>@@ -103,7 +106,6 @@ import { useReviewPolicyByEnvironmentName } from "@/store";import {GeneralErrorCode,RuleTemplate,- RuleType,SQLReviewPolicyErrorCode,UNKNOWN_ENVIRONMENT_NAME,findRuleTemplate,@@ -200,7 +202,7 @@ const categoryAndTitle = (const title = messageWithCode(checkResult.title, code);return ["", title];}- const rule = ruleTemplateMap.get(checkResult.title as RuleType);+ const rule = ruleTemplateMap.get(checkResult.title);if (rule) {const ruleLocalization = getRuleLocalization(rule.type);const key = `sql-review.category.${rule.category.toLowerCase()}`;@@ -279,7 +281,7 @@ const reviewPolicy = useReviewPolicyByEnvironmentName(return props.environment || UNKNOWN_ENVIRONMENT_NAME;}));-const getActiveRule = (type: RuleType): PreviewSQLReviewRule | undefined => {+const getActiveRule = (type: string): PreviewSQLReviewRule | undefined => {const rule = reviewPolicy.value?.ruleList.find((rule) => rule.type === type);if (!rule) {return undefined;@@ -304,7 +306,7 @@ const getActiveRule = (type: RuleType): PreviewSQLReviewRule | undefined => {payload: payload,};};-const setActiveRule = (type: RuleType) => {+const setActiveRule = (type: string) => {state.activeRule = getActiveRule(type);};</script>diff --git a/frontend/src/components/SQLReview/SQLReviewCreation.vue b/frontend/src/components/SQLReview/SQLReviewCreation.vueindex 0450cdbc44..817b37a7f5 100644--- a/frontend/src/components/SQLReview/SQLReviewCreation.vue+++ b/frontend/src/components/SQLReview/SQLReviewCreation.vue@@ -191,6 +191,7 @@ const changeStepIndex = (nextIndex: number) => {positiveText: t("common.confirm"),onPositiveClick: (_: MouseEvent) => {onTemplateApply(state.pendingApplyTemplate);+ state.currentStep = nextIndex;},});return;diff --git a/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue b/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vueindex dcccb32d20..659948bde1 100644--- a/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue+++ b/frontend/src/components/SQLReview/components/SQLReviewCategoryTabFilter.vue@@ -3,8 +3,8 @@:value="state.selectedTab":items="tabItemList"@update:value="- (val) => {- state.selectedTab = val as string;+ (val: string) => {+ state.selectedTab = val;$emit('update:value', val == 'all' ? undefined : state.selectedTab);}"@@ -14,10 +14,9 @@<script lang="ts" setup>import { computed, reactive, watch } from "vue";import { useI18n } from "vue-i18n";-import { CategoryType } from "@/types/sqlReview";export interface CategoryFilterItem {- id: CategoryType;+ id: string;name: string;}diff --git a/frontend/src/components/SQLReview/components/utils.ts b/frontend/src/components/SQLReview/components/utils.tsindex 94775f667d..6593d1265a 100644--- a/frontend/src/components/SQLReview/components/utils.ts+++ b/frontend/src/components/SQLReview/components/utils.ts@@ -3,7 +3,6 @@ import {convertPolicyRuleToRuleTemplate,RuleConfigComponent,RuleTemplate,- RuleType,SQLReviewPolicy,TEMPLATE_LIST,IndividualConfigForEngine,@@ -22,20 +21,20 @@ export const rulesToTemplate = (withDisabled = false) => {const ruleTemplateList: RuleTemplate[] = [];- const ruleTemplateMap: Map<RuleType, RuleTemplate> = TEMPLATE_LIST.reduce(+ const ruleTemplateMap: Map<string, RuleTemplate> = TEMPLATE_LIST.reduce((map, template) => {for (const rule of template.ruleList) {map.set(rule.type, rule);}return map;},- new Map<RuleType, RuleTemplate>()+ new Map<string, RuleTemplate>());const groupByRule = groupBy(review.ruleList, (rule) => rule.type);for (const [type, ruleList] of Object.entries(groupByRule)) {- const rule = ruleTemplateMap.get(type as RuleType);+ const rule = ruleTemplateMap.get(type);if (!rule) {continue;}diff --git a/frontend/src/router/dashboard/workspaceSetting.ts b/frontend/src/router/dashboard/workspaceSetting.tsindex 1cfa3bab82..666c2f2926 100644--- a/frontend/src/router/dashboard/workspaceSetting.ts+++ b/frontend/src/router/dashboard/workspaceSetting.ts@@ -224,7 +224,10 @@ const workspaceSettingRoutes: RouteRecordRaw[] = [meta: {title: (route: RouteLocationNormalized) => {const slug = route.params.vcsSlug as string;- return useVCSV1Store().getVCSByUid(uidFromSlug(slug))?.title ?? "";+ return (+ useVCSV1Store().getVCSByUid(uidFromSlug(slug))?.title ??+ t("settings.sidebar.gitops")+ );},requiredWorkspacePermissionList: () => ["bb.externalVersionControls.get",@@ -281,7 +284,7 @@ const workspaceSettingRoutes: RouteRecordRaw[] = [return (useSQLReviewStore().getReviewPolicyByEnvironmentId(String(uidFromSlug(slug))- )?.name ?? ""+ )?.name ?? t("sql-review.title"));},requiredWorkspacePermissionList: () => ["bb.policies.get"],diff --git a/frontend/src/store/modules/sqlReview.ts b/frontend/src/store/modules/sqlReview.tsindex de21c71332..91ce07d7e3 100644--- a/frontend/src/store/modules/sqlReview.ts+++ b/frontend/src/store/modules/sqlReview.ts@@ -11,7 +11,6 @@ import {SQLReviewPolicy,IdType,MaybeRef,- RuleType,} from "@/types";import { Environment } from "@/types/proto/v1/environment_service";import {@@ -35,7 +34,7 @@ const convertToSQLReviewPolicy = async (const ruleList: SchemaPolicyRule[] = [];for (const r of policy.sqlReviewPolicy.rules) {const rule: SchemaPolicyRule = {- type: r.type as RuleType,+ type: r.type,level: r.level,engine: r.engine,comment: r.comment,diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yamlindex 192f895550..ce5d88efc7 100644--- a/frontend/src/types/sql-review-schema.yaml+++ b/frontend/src/types/sql-review-schema.yaml@@ -1,21 +1,9 @@-categoryList:- - ENGINE- - INDEX- - NAMING- - STATEMENT- - TABLE- - SCHEMA- - COLUMN- - SYSTEM- - DATABASE- - ADVICEruleList:- type: engine.mysql.use-innodbcategory: ENGINEengineList:- MYSQL- MARIADB- componentList: []- type: table.require-pkcategory: TABLEengineList:@@ -28,7 +16,6 @@ ruleList:- SNOWFLAKE- MSSQL- MARIADB- componentList: []- type: table.no-foreign-keycategory: TABLEengineList:@@ -41,7 +28,6 @@ ruleList:- SNOWFLAKE- MSSQL- MARIADB- componentList: []- type: table.drop-naming-conventioncategory: TABLEengineList:@@ -81,17 +67,14 @@ ruleList:- POSTGRES- OCEANBASE- MARIADB- componentList: []- type: table.disallow-triggercategory: TABLEengineList:- MYSQL- componentList: []- type: table.no-duplicate-indexcategory: TABLEengineList:- MYSQL- componentList: []- type: table.text-fields-total-lengthcategory: TABLEengineList:@@ -105,7 +88,6 @@ ruleList:category: TABLEengineList:- MYSQL- componentList: []- type: statement.select.no-select-allcategory: STATEMENTengineList:@@ -118,7 +100,6 @@ ruleList:- SNOWFLAKE- MSSQL- MARIADB- componentList: []- type: statement.where.requirecategory: STATEMENTengineList:@@ -131,7 +112,6 @@ ruleList:- SNOWFLAKE- MSSQL- MARIADB- componentList: []- type: statement.where.no-leading-wildcard-likecategory: STATEMENTengineList:@@ -142,12 +122,10 @@ ruleList:- OCEANBASE_ORACLE- OCEANBASE- MARIADB- componentList: []- type: statement.disallow-cascadecategory: STATEMENTengineList:- POSTGRES- componentList: []- type: statement.disallow-commitcategory: STATEMENTengineList:@@ -156,7 +134,6 @@ ruleList:- POSTGRES- OCEANBASE- MARIADB- componentList: []- type: statement.disallow-limitcategory: STATEMENTengineList:@@ -164,7 +141,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: statement.disallow-order-bycategory: STATEMENTengineList:@@ -172,7 +148,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: statement.merge-alter-tablecategory: STATEMENTengineList:@@ -181,7 +156,6 @@ ruleList:- POSTGRES- OCEANBASE- MARIADB- componentList: []- type: statement.insert.row-limitcategory: STATEMENTengineList:@@ -204,7 +178,6 @@ ruleList:- OCEANBASE_ORACLE- OCEANBASE- MARIADB- componentList: []- type: statement.insert.disallow-order-by-randcategory: STATEMENTengineList:@@ -213,7 +186,6 @@ ruleList:- POSTGRES- OCEANBASE- MARIADB- componentList: []- type: statement.affected-row-limitcategory: STATEMENTengineList:@@ -234,59 +206,48 @@ ruleList:- OCEANBASE- MARIADB- TIDB- componentList: []- type: statement.disallow-add-column-with-defaultcategory: STATEMENTengineList:- POSTGRES- componentList: []- type: statement.add-check-not-validcategory: STATEMENTengineList:- POSTGRES- componentList: []- type: statement.disallow-add-not-nullcategory: STATEMENTengineList:- POSTGRES- componentList: []- type: statement.select-full-table-scancategory: STATEMENTengineList:- MYSQL- OCEANBASE- MARIADB- componentList: []- type: statement.create-specify-schemacategory: STATEMENTengineList:- POSTGRES- componentList: []- type: statement.check-set-role-variablecategory: STATEMENTengineList:- POSTGRES- componentList: []- type: statement.disallow-using-temporarycategory: STATEMENTengineList:- MYSQL- componentList: []- type: statement.disallow-using-filesortcategory: STATEMENTengineList:- MYSQL- componentList: []- type: statement.where.no-equal-nullcategory: STATEMENTengineList:- MYSQL- componentList: []- type: statement.where.disallow-using-functioncategory: STATEMENTengineList:- MYSQL- componentList: []- type: statement.where.statement.query.minimum-plan-levelcategory: STATEMENTengineList:@@ -336,17 +297,14 @@ ruleList:category: STATEMENTengineList:- MYSQL- componentList: []- type: statement.disallow-mix-dmlcategory: STATEMENTengineList:- MYSQL- componentList: []- type: statement.disallow-mix-ddl-dmlcategory: STATEMENTengineList:- MYSQL- componentList: []- type: naming.tablecategory: NAMINGengineList:@@ -486,7 +444,6 @@ ruleList:- OCEANBASE_ORACLE- SNOWFLAKE- MSSQL- componentList: []- type: naming.identifier.no-keywordcategory: NAMINGengineList:@@ -495,7 +452,6 @@ ruleList:- SNOWFLAKE- MSSQL- MYSQL- componentList: []- type: naming.identifier.casecategory: NAMINGengineList:@@ -560,7 +516,6 @@ ruleList:- SNOWFLAKE- MSSQL- MARIADB- componentList: []- type: column.disallow-change-typecategory: COLUMNengineList:@@ -569,7 +524,6 @@ ruleList:- POSTGRES- OCEANBASE- MARIADB- componentList: []- type: column.set-default-for-not-nullcategory: COLUMNengineList:@@ -579,7 +533,6 @@ ruleList:- OCEANBASE_ORACLE- OCEANBASE- MARIADB- componentList: []- type: column.disallow-changecategory: COLUMNengineList:@@ -587,7 +540,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.disallow-changing-ordercategory: COLUMNengineList:@@ -595,7 +547,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.disallow-drop-in-indexcategory: COLUMNengineList:@@ -603,7 +554,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.commentcategory: COLUMNengineList:@@ -627,7 +577,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.type-disallow-listcategory: COLUMNengineList:@@ -650,7 +599,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.maximum-character-lengthcategory: COLUMNengineList:@@ -700,7 +648,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.current-time-count-limitcategory: COLUMNengineList:@@ -708,7 +655,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: column.require-defaultcategory: COLUMNengineList:@@ -719,7 +665,6 @@ ruleList:- OCEANBASE_ORACLE- OCEANBASE- MARIADB- componentList: []- type: schema.backward-compatibilitycategory: SCHEMAengineList:@@ -730,7 +675,6 @@ ruleList:- SNOWFLAKE- MSSQL- MARIADB- componentList: []- type: database.drop-empty-databasecategory: DATABASEengineList:@@ -738,7 +682,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: index.no-duplicate-columncategory: INDEXengineList:@@ -747,7 +690,6 @@ ruleList:- POSTGRES- OCEANBASE- MARIADB- componentList: []- type: index.key-number-limitcategory: INDEXengineList:@@ -770,7 +712,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: index.type-no-blobcategory: INDEXengineList:@@ -778,7 +719,6 @@ ruleList:- TIDB- OCEANBASE- MARIADB- componentList: []- type: index.total-number-limitcategory: INDEXengineList:@@ -808,7 +748,6 @@ ruleList:category: INDEXengineList:- POSTGRES- componentList: []- type: index.type-allow-listcategory: INDEXengineList:@@ -857,22 +796,18 @@ ruleList:category: SYSTEMengineList:- MYSQL- componentList: []- type: system.event.disallow-createcategory: SYSTEMengineList:- MYSQL- componentList: []- type: system.view.disallow-createcategory: SYSTEMengineList:- MYSQL- componentList: []- type: system.function.disallow-createcategory: SYSTEMengineList:- MYSQL- componentList: []- type: system.function.disallowed-listcategory: SYSTEMengineList:diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.tsindex f0c6f914b3..cce070a39c 100644--- a/frontend/src/types/sqlReview.ts+++ b/frontend/src/types/sqlReview.ts@@ -13,19 +13,6 @@ import sqlReviewDevTemplate from "./sql-review.dev.yaml";import sqlReviewProdTemplate from "./sql-review.prod.yaml";import sqlReviewSampleTemplate from "./sql-review.sample.yaml";-// The category type for rule template-export type CategoryType =- | "ENGINE"- | "NAMING"- | "STATEMENT"- | "TABLE"- | "COLUMN"- | "SCHEMA"- | "DATABASE"- | "INDEX"- | "SYSTEM"- | "ADVICE";-export const LEVEL_LIST = [SQLReviewRuleLevel.ERROR,SQLReviewRuleLevel.WARNING,@@ -97,94 +84,6 @@ export interface RuleConfigComponent {| BooleanPayload;}-// The identifier for rule template-export type RuleType =- | "engine.mysql.use-innodb"- | "table.require-pk"- | "table.no-foreign-key"- | "table.drop-naming-convention"- | "table.disallow-partition"- | "table.disallow-trigger"- | "table.no-duplicate-index"- | "table.text-fields-total-length"- | "table.disallow-set-charset"- | "table.comment"- | "naming.table"- | "naming.column"- | "naming.index.uk"- | "naming.index.pk"- | "naming.index.fk"- | "naming.index.idx"- | "naming.column.auto-increment"- | "naming.table.no-keyword"- | "naming.identifier.no-keyword"- | "naming.identifier.case"- | "column.required"- | "column.no-null"- | "column.comment"- | "column.type-disallow-list"- | "column.disallow-change-type"- | "column.disallow-drop-in-index"- | "column.set-default-for-not-null"- | "column.disallow-change"- | "column.disallow-changing-order"- | "column.auto-increment-must-integer"- | "column.disallow-set-charset"- | "column.auto-increment-must-unsigned"- | "column.maximum-character-length"- | "column.maximum-varchar-length"- | "column.auto-increment-initial-value"- | "column.current-time-count-limit"- | "column.require-default"- | "statement.select.no-select-all"- | "statement.where.require"- | "statement.where.no-leading-wildcard-like"- | "statement.disallow-commit"- | "statement.disallow-limit"- | "statement.disallow-order-by"- | "statement.merge-alter-table"- | "statement.insert.must-specify-column"- | "statement.insert.disallow-order-by-rand"- | "statement.insert.row-limit"- | "statement.affected-row-limit"- | "statement.dml-dry-run"- | "statement.disallow-add-column-with-default"- | "statement.add-check-not-valid"- | "statement.disallow-add-not-null"- | "statement.select-full-table-scan"- | "statement.create-specify-schema"- | "statement.check-set-role-variable"- | "statement.disallow-using-temporary"- | "statement.disallow-using-filesort"- | "statement.where.no-equal-null"- | "statement.where.disallow-using-function"- | "statement.where.statement.query.minimum-plan-level"- | "statement.where.maximum-logical-operator-count"- | "statement.maximum-limit-value"- | "statement.maximum-join-table-count"- | "statement.maximum-statements-in-transaction"- | "statement.join-strict-column-attrs"- | "statement.disallow-mix-dml"- | "statement.disallow-mix-ddl-dml"- | "schema.backward-compatibility"- | "database.drop-empty-database"- | "system.charset.allowlist"- | "system.collation.allowlist"- | "system.comment.length"- | "system.procedure.disallow-create"- | "system.event.disallow-create"- | "system.view.disallow-create"- | "system.function.disallow-create"- | "system.function.disallowed-list"- | "index.no-duplicate-column"- | "index.type-no-blob"- | "index.key-number-limit"- | "index.total-number-limit"- | "index.primary-key-type-allowlist"- | "index.create-concurrently"- | "index.pk-type-limit"- | "advice.online-migration";-// The naming format rule payload.// Used by the backend.interface NamingFormatPayload {@@ -220,7 +119,7 @@ interface CasePayload {// The SchemaPolicyRule stores the rule configuration by users.// Used by the backendexport interface SchemaPolicyRule {- type: RuleType;+ type: string;level: SQLReviewRuleLevel;engine: Engine;payload?:@@ -248,8 +147,8 @@ export interface SQLReviewPolicy {// RuleTemplate is the rule template. Used by the frontendexport interface RuleTemplate {- type: RuleType;- category: CategoryType;+ type: string;+ category: string;engineList: Engine[];componentList: RuleConfigComponent[];individualConfigList: IndividualConfigForEngine[];@@ -267,10 +166,14 @@ export interface SQLReviewPolicyTemplate {export const TEMPLATE_LIST: SQLReviewPolicyTemplate[] = (function () {const ruleSchemaMap = (sqlReviewSchema.ruleList as RuleTemplate[]).reduce((map, ruleSchema) => {- map.set(ruleSchema.type, ruleSchema);+ map.set(ruleSchema.type, {+ ...ruleSchema,+ componentList: ruleSchema.componentList || [],+ individualConfigList: ruleSchema.individualConfigList || [],+ });return map;},- new Map<RuleType, RuleTemplate>()+ new Map<string, RuleTemplate>());interface PayloadObject {@@ -283,7 +186,7 @@ export const TEMPLATE_LIST: SQLReviewPolicyTemplate[] = (function () {] as {id: string;ruleList: {- type: RuleType;+ type: string;level: SQLReviewRuleLevel;payload?: PayloadObject;engine?: Engine;@@ -295,7 +198,7 @@ export const TEMPLATE_LIST: SQLReviewPolicyTemplate[] = (function () {const groupRuleList = groupBy(template.ruleList, (rule) => rule.type);for (const [ruleType, groupList] of Object.entries(groupRuleList)) {- const ruleTemplate = ruleSchemaMap.get(ruleType as RuleType);+ const ruleTemplate = ruleSchemaMap.get(ruleType);if (!ruleTemplate) {continue;}@@ -364,7 +267,7 @@ export const TEMPLATE_LIST: SQLReviewPolicyTemplate[] = (function () {});})();-export const findRuleTemplate = (type: RuleType) => {+export const findRuleTemplate = (type: string) => {for (let i = 0; i < TEMPLATE_LIST.length; i++) {const template = TEMPLATE_LIST[i];const rule = template.ruleList.find((rule) => rule.type === type);@@ -373,16 +276,18 @@ export const findRuleTemplate = (type: RuleType) => {return undefined;};-export const ruleTemplateMap: Map<RuleType, RuleTemplate> =- TEMPLATE_LIST.reduce((map, template) => {+export const ruleTemplateMap: Map<string, RuleTemplate> = TEMPLATE_LIST.reduce(+ (map, template) => {for (const rule of template.ruleList) {map.set(rule.type, rule);}return map;- }, new Map<RuleType, RuleTemplate>());+ },+ new Map<string, RuleTemplate>()+);interface RuleCategory {- id: CategoryType;+ id: string;ruleList: RuleTemplate[];}@@ -390,12 +295,6 @@ interface RuleCategory {export const convertToCategoryList = (ruleList: RuleTemplate[]): RuleCategory[] => {- const categoryList = sqlReviewSchema.categoryList as CategoryType[];- const categoryOrder = categoryList.reduce((map, category, index) => {- map.set(category, index);- return map;- }, new Map<CategoryType, number>());-const dict = ruleList.reduce((dict, rule) => {if (!dict[rule.category]) {dict[rule.category] = {@@ -407,11 +306,7 @@ export const convertToCategoryList = (return dict;}, {} as { [key: string]: RuleCategory });- return Object.values(dict).sort(- (c1, c2) =>- (categoryOrder.get(c2.id as CategoryType) || 0) -- (categoryOrder.get(c1.id as CategoryType) || 0)- );+ return Object.values(dict);};const mergeRulePayloadAsIndividualConfig = (@@ -454,7 +349,8 @@ export const convertPolicyRuleToRuleTemplate = (comment: policyRule.comment,};- if (ruleTemplate.componentList.length === 0) {+ const componentList = ruleTemplate.componentList ?? [];+ if (componentList.length === 0) {return res;}@@ -475,21 +371,23 @@ export const convertPolicyRuleToRuleTemplate = (policyRule = policyRuleList[0];const payload = policyRule?.payload ?? {};- const stringComponent = ruleTemplate.componentList.find(+ const stringComponent = componentList.find((c) => c.payload.type === "STRING");- const numberComponent = ruleTemplate.componentList.find(+ const numberComponent = componentList.find((c) => c.payload.type === "NUMBER");- const booleanComponent = ruleTemplate.componentList.find(+ const booleanComponent = componentList.find((c) => c.payload.type === "BOOLEAN");- const templateComponent = ruleTemplate.componentList.find(+ const templateComponent = componentList.find((c) => c.payload.type === "TEMPLATE");switch (ruleTemplate.type) {+ // Following rules require STRING component.case "table.drop-naming-convention":+ case "statement.where.statement.query.minimum-plan-level":if (!stringComponent) {throw new Error(`Invalid rule ${ruleTemplate.type}`);}@@ -507,6 +405,7 @@ export const convertPolicyRuleToRuleTemplate = (],individualConfigList,};+ // Following rules require STRING and NUMBER component.case "naming.column":case "naming.column.auto-increment":case "naming.table":@@ -534,6 +433,7 @@ export const convertPolicyRuleToRuleTemplate = (],individualConfigList,};+ // Following rules require TEMPLATE component.case "naming.index.pk":if (!templateComponent) {throw new Error(`Invalid rule ${ruleTemplate.type}`);@@ -552,6 +452,7 @@ export const convertPolicyRuleToRuleTemplate = (],individualConfigList,};+ // Following rules require TEMPLATE and NUMBER component.case "naming.index.idx":case "naming.index.uk":case "naming.index.fk":@@ -579,6 +480,7 @@ export const convertPolicyRuleToRuleTemplate = (],individualConfigList,};+ // Following rules require BOOLEAN component.case "naming.identifier.case":if (!booleanComponent) {throw new Error(`Invalid rule ${ruleTemplate.type}`);@@ -594,7 +496,7 @@ export const convertPolicyRuleToRuleTemplate = (individualConfigList,};case "column.required": {- const requiredColumnComponent = ruleTemplate.componentList[0];+ const requiredColumnComponent = componentList[0];// The columnList payload is deprecated.// Just keep it to compatible with old data, we can remove this later.let value: string[] = (payload as any)["columnList"];@@ -616,13 +518,14 @@ export const convertPolicyRuleToRuleTemplate = (individualConfigList,};}+ // Following rules require STRING_ARRAY component.case "column.type-disallow-list":case "index.primary-key-type-allowlist":case "index.type-allow-list":case "system.charset.allowlist":case "system.collation.allowlist":case "system.function.disallowed-list": {- const stringArrayComponent = ruleTemplate.componentList[0];+ const stringArrayComponent = componentList[0];const stringArrayPayload = {...stringArrayComponent.payload,value: (payload as StringArrayLimitPayload).list,@@ -638,6 +541,7 @@ export const convertPolicyRuleToRuleTemplate = (individualConfigList,};}+ // Following rules require BOOLEAN and NUMBER component.case "column.comment":case "table.comment":if (!booleanComponent || !numberComponent) {@@ -664,6 +568,7 @@ export const convertPolicyRuleToRuleTemplate = (],individualConfigList,};+ // Following rules require NUMBER component.case "statement.insert.row-limit":case "statement.affected-row-limit":case "column.maximum-character-length":@@ -673,6 +578,11 @@ export const convertPolicyRuleToRuleTemplate = (case "index.total-number-limit":case "system.comment.length":case "advice.online-migration":+ case "table.text-fields-total-length":+ case "statement.where.maximum-logical-operator-count":+ case "statement.maximum-limit-value":+ case "statement.maximum-join-table-count":+ case "statement.maximum-statements-in-transaction":if (!numberComponent) {throw new Error(`Invalid rule ${ruleTemplate.type}`);}@@ -699,24 +609,24 @@ const mergeIndividualConfigAsRule = (base: SchemaPolicyRule,template: RuleTemplate): SchemaPolicyRule => {- const stringPayload = template.componentList.find(- (c) => c.payload.type === "STRING"- )?.payload as StringPayload | undefined;- const numberPayload = template.componentList.find(- (c) => c.payload.type === "NUMBER"- )?.payload as NumberPayload | undefined;- const templatePayload = template.componentList.find(+ const componentList = template.componentList ?? [];+ const stringPayload = componentList.find((c) => c.payload.type === "STRING")+ ?.payload as StringPayload | undefined;+ const numberPayload = componentList.find((c) => c.payload.type === "NUMBER")+ ?.payload as NumberPayload | undefined;+ const templatePayload = componentList.find((c) => c.payload.type === "TEMPLATE")?.payload as TemplatePayload | undefined;- const booleanPayload = template.componentList.find(- (c) => c.payload.type === "BOOLEAN"- )?.payload as BooleanPayload | undefined;- const stringArrayPayload = template.componentList.find(+ const booleanPayload = componentList.find((c) => c.payload.type === "BOOLEAN")+ ?.payload as BooleanPayload | undefined;+ const stringArrayPayload = componentList.find((c) => c.payload.type === "STRING_ARRAY")?.payload as StringArrayPayload | undefined;switch (template.type) {+ // Following rules require STRING component.case "table.drop-naming-convention":+ case "statement.where.statement.query.minimum-plan-level":if (!stringPayload) {throw new Error(`Invalid rule ${template.type}`);}@@ -727,6 +637,7 @@ const mergeIndividualConfigAsRule = (format: stringPayload.value ?? stringPayload.default,},};+ // Following rules require STRING and NUMBER component.case "naming.column":case "naming.column.auto-increment":case "naming.table":@@ -741,6 +652,7 @@ const mergeIndividualConfigAsRule = (maxLength: numberPayload.value ?? numberPayload.default,},};+ // Following rules require TEMPLATE component.case "naming.index.pk":if (!templatePayload) {throw new Error(`Invalid rule ${template.type}`);@@ -751,6 +663,7 @@ const mergeIndividualConfigAsRule = (format: templatePayload.value ?? templatePayload.default,},};+ // Following rules require TEMPLATE and NUMBER component.case "naming.index.idx":case "naming.index.uk":case "naming.index.fk":@@ -764,6 +677,7 @@ const mergeIndividualConfigAsRule = (maxLength: numberPayload.value ?? numberPayload.default,},};+ // Following rules require BOOLEAN component.case "naming.identifier.case":if (!booleanPayload) {throw new Error(`Invalid rule ${template.type}`);@@ -774,6 +688,7 @@ const mergeIndividualConfigAsRule = (upper: booleanPayload.value ?? booleanPayload.default,},};+ // Following rules require STRING_ARRAY component.case "column.required":case "column.type-disallow-list":case "index.primary-key-type-allowlist":@@ -791,6 +706,7 @@ const mergeIndividualConfigAsRule = (},};}+ // Following rules require BOOLEAN and NUMBER component.case "column.comment":case "table.comment":if (!booleanPayload || !numberPayload) {@@ -803,6 +719,7 @@ const mergeIndividualConfigAsRule = (maxLength: numberPayload.value ?? numberPayload.default,},};+ // Following rules require NUMBER component.case "statement.insert.row-limit":case "statement.affected-row-limit":case "column.maximum-character-length":@@ -812,6 +729,11 @@ const mergeIndividualConfigAsRule = (case "index.total-number-limit":case "system.comment.length":case "advice.online-migration":+ case "table.text-fields-total-length":+ case "statement.where.maximum-logical-operator-count":+ case "statement.maximum-limit-value":+ case "statement.maximum-join-table-count":+ case "statement.maximum-statements-in-transaction":if (!numberPayload) {throw new Error(`Invalid rule ${template.type}`);}@@ -837,13 +759,13 @@ export const convertRuleTemplateToPolicyRule = (engine,comment: rule.comment ?? "",}));- if (rule.componentList.length === 0) {+ if ((rule.componentList?.length ?? 0) === 0) {return baseList;}return baseList.map((base) => {const result = mergeIndividualConfigAsRule(base, rule);- const individualConfig = rule.individualConfigList.find(+ const individualConfig = (rule.individualConfigList || []).find((config) => config.engine === base.engine);if (individualConfig && result.payload) {@@ -855,12 +777,12 @@ export const convertRuleTemplateToPolicyRule = (});};-export const getRuleLocalizationKey = (type: RuleType): string => {+export const getRuleLocalizationKey = (type: string): string => {return type.split(".").join("-");};export const getRuleLocalization = (- type: RuleType+ type: string): { title: string; description: string } => {const { t } = useI18n();const key = getRuleLocalizationKey(type);@@ -875,7 +797,7 @@ export const getRuleLocalization = (};export const ruleIsAvailableInSubscription = (- ruleType: RuleType,+ ruleType: string,subscriptionPlan: PlanType): boolean => {return true;diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vueindex 7f7777569c..54e4c646a6 100644--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue@@ -38,8 +38,10 @@:required="true":focus-on-mount="false":ends-on-enter="true"- :bordered="false"+ :bordered="state.editingTitle":value="reviewPolicy.name"+ size="large"+ @on-focus="state.editingTitle = true"@end-editing="changeName"/></div>@@ -156,7 +158,6 @@ import {unknown,RuleTemplate,SQLReviewPolicy,- RuleType,SchemaPolicyRule,TEMPLATE_LIST,convertPolicyRuleToRuleTemplate,@@ -181,6 +182,7 @@ interface LocalState {ruleList: RuleTemplate[];rulesUpdated: boolean;updating: boolean;+ editingTitle: boolean;}const { t } = useI18n();@@ -198,6 +200,7 @@ const state = reactive<LocalState>({ruleList: [],rulesUpdated: false,updating: false,+ editingTitle: false,});watchEffect(async () => {@@ -224,20 +227,20 @@ const ruleListOfPolicy = computed((): RuleTemplate[] => {}const ruleTemplateList: RuleTemplate[] = [];- const ruleTemplateMap: Map<RuleType, RuleTemplate> = TEMPLATE_LIST.reduce(+ const ruleTemplateMap: Map<string, RuleTemplate> = TEMPLATE_LIST.reduce((map, template) => {for (const rule of template.ruleList) {map.set(rule.type, rule);}return map;},- new Map<RuleType, RuleTemplate>()+ new Map<string, RuleTemplate>());const groupByRule = groupBy(reviewPolicy.value.ruleList, (rule) => rule.type);for (const [type, ruleList] of Object.entries(groupByRule)) {- const rule = ruleTemplateMap.get(type as RuleType);+ const rule = ruleTemplateMap.get(type);if (!rule) {continue;}@@ -245,7 +248,7 @@ const ruleListOfPolicy = computed((): RuleTemplate[] => {const data = convertPolicyRuleToRuleTemplate(ruleList, rule);if (data) {ruleTemplateList.push(data);- ruleTemplateMap.delete(type as RuleType);+ ruleTemplateMap.delete(type);}}@@ -274,6 +277,7 @@ const {} = useSQLRuleFilter(toRef(state, "ruleList"));const changeName = async (name: string) => {+ state.editingTitle = false;const policy = reviewPolicy.value;if (name === policy.name) {return;