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: extract yaml file for schema review configuration (#1750)
ecmadao8dccdbac36f9
diff --git a/frontend/package.json b/frontend/package.jsonindex e67f51d8b1..a56308e43f 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -39,6 +39,7 @@"vueuc": "^0.4.27"},"devDependencies": {+ "@rollup/plugin-yaml": "^3.1.0","@iconify/json": "^1.1.432","@intlify/vite-plugin-vue-i18n": "^3.2.1","@tailwindcss/forms": "^0.5.0",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex c25037865d..95c9b960a1 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -4,6 +4,7 @@ specifiers:'@bytebase/vue-kbar': ^0.1.6'@iconify/json': ^1.1.432'@intlify/vite-plugin-vue-i18n': ^3.2.1+ '@rollup/plugin-yaml': ^3.1.0'@soerenmartius/vue3-clipboard': ^0.1.2'@tailwindcss/forms': ^0.5.0'@tailwindcss/line-clamp': ^0.3.1@@ -90,6 +91,7 @@ dependencies:devDependencies:'@iconify/json': 1.1.461'@intlify/vite-plugin-vue-i18n': 3.3.1_5zistg762mnnb5dqki47v4swhy+ '@rollup/plugin-yaml': 3.1.0'@tailwindcss/forms': [email protected]'@tailwindcss/line-clamp': [email protected]'@tailwindcss/typography': [email protected]@@ -398,6 +400,28 @@ packages:fastq: 1.13.0dev: true+ /@rollup/plugin-yaml/3.1.0:+ resolution: {integrity: sha512-61PsAXqN7YNYdg/nezK3NkqAu6e3Qu2wjHYW3r52Nx0aLi+rG7gkkIqtvxG8EtSqE2rra5CUcWBZj+v362qt9A==}+ engines: {node: '>=10.0.0'}+ peerDependencies:+ rollup: ^1.20.0 || ^2.0.0+ dependencies:+ '@rollup/pluginutils': 3.1.0+ js-yaml: 3.14.1+ tosource: 1.0.0+ dev: true++ /@rollup/pluginutils/3.1.0:+ resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==}+ engines: {node: '>= 8.0.0'}+ peerDependencies:+ rollup: ^1.20.0||^2.0.0+ dependencies:+ '@types/estree': 0.0.39+ estree-walker: 1.0.1+ picomatch: 2.3.1+ dev: true+/@rollup/pluginutils/4.2.0:resolution: {integrity: sha512-2WUyJNRkyH5p487pGnn4tWAsxhEFKN/pT8CMgHshd5H+IXkOnKvKZwsz5ZWz+YCXkleZRAU5kwbfgF8CPfDRqA==}engines: {node: '>= 8.0.0'}@@ -450,6 +474,10 @@ packages:resolution: {integrity: sha512-/ceqdqeRraGolFTcfoXNiqjyQhZzbINDngeoAq9GoHa8PPK1yNzTaxWjA6BFWp5Ua9JpXEMSS4s5i9tS0hOJtw==}dev: true+ /@types/estree/0.0.39:+ resolution: {integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==}+ dev: true+/@types/jest/27.4.1:resolution: {integrity: sha512-23iPJADSmicDVrWk+HT58LMJtzLAnB2AgIzplQuq/bSrGaxCrlvRFjGbXmamnnk/mAmCdLStiGqggu28ocUyiw==}dependencies:@@ -940,6 +968,12 @@ packages:resolution: {integrity: sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==}dev: true+ /argparse/1.0.10:+ resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}+ dependencies:+ sprintf-js: 1.0.3+ dev: true+/argparse/2.0.1:resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}@@ -1658,6 +1692,12 @@ packages:eslint-visitor-keys: 3.3.0dev: true+ /esprima/4.0.1:+ resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==}+ engines: {node: '>=4'}+ hasBin: true+ dev: true+/esquery/1.4.0:resolution: {integrity: sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==}engines: {node: '>=0.10'}@@ -1682,6 +1722,10 @@ packages:engines: {node: '>=4.0'}dev: true+ /estree-walker/1.0.1:+ resolution: {integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==}+ dev: true+/estree-walker/2.0.2:resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}@@ -2030,6 +2074,14 @@ packages:resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}dev: true+ /js-yaml/3.14.1:+ resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==}+ hasBin: true+ dependencies:+ argparse: 1.0.10+ esprima: 4.0.1+ dev: true+/js-yaml/4.1.0:resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}hasBin: true@@ -2617,6 +2669,10 @@ packages:resolution: {integrity: sha512-VUkxDJfIGSvTM/fm/+OSrx8ha9URwE/9B8FPvfzoBuAxVELIHBWpsfnJXIXv77zVwuex//QQL4kTU9SDBPeHjA==}dev: false+ /sprintf-js/1.0.3:+ resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==}+ dev: true+/sql-formatter/4.0.2:resolution: {integrity: sha512-R6u9GJRiXZLr/lDo8p56L+OyyN2QFJPCDnsyEOsbdIpsnDKL8gubYFo7lNR7Zx7hfdWT80SfkoVS0CMaF/DE2w==}hasBin: true@@ -2725,6 +2781,11 @@ packages:is-number: 7.0.0dev: true+ /tosource/1.0.0:+ resolution: {integrity: sha512-N6g8eQ1eerw6Y1pBhdgkubWIiPFwXa2POSUrlL8jth5CyyEWNWzoGKRkO3CaO7Jx27hlJP54muB3btIAbx4MPg==}+ engines: {node: '>=0.4.0'}+ dev: true+/treemate/0.3.11:resolution: {integrity: sha512-M8RGFoKtZ8dF+iwJfAJTOH/SM4KluKOKRJpjCMhI8bG3qB74zrFoArKZ62ll0Fr3mqkMJiQOmWYkdYgDeITYQg==}dev: falsediff --git a/frontend/src/assets/mysql.dev.png b/frontend/src/assets/mysql.dev.pngnew file mode 100644index 0000000000..b02875845eBinary files /dev/null and b/frontend/src/assets/mysql.dev.png differdiff --git a/frontend/src/assets/mysql.prod.png b/frontend/src/assets/mysql.prod.pngnew file mode 100644index 0000000000..5480b137ceBinary files /dev/null and b/frontend/src/assets/mysql.prod.png differdiff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vueindex 19d5f56352..380d30a43e 100644--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue@@ -79,12 +79,9 @@ import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { BBStepTabItem } from "@/bbkit/types";import {- RuleType,- ruleTemplateList,- RuleLevel,Environment,RuleTemplate,- SchemaReviewPolicyTemplate,+ TEMPLATE_LIST,convertRuleTemplateToPolicyRule,} from "@/types";import {@@ -138,87 +135,6 @@ const hasSchemaReviewPolicyFeature = featureToRef("bb.feature.schema-review-policy");-const getRuleListWithLevel = (- typeList: RuleType[],- level: RuleLevel-): RuleTemplate[] => {- return typeList.reduce((res, type) => {- const rule = ruleTemplateList.find((r) => r.type === type);- if (!rule) {- return res;- }-- res.push({- ...rule,- level,- });- return res;- }, [] as RuleTemplate[]);-};--const TEMPLATE_LIST: SchemaReviewPolicyTemplate[] = [- {- title: t("schema-review-policy.template.policy-for-prod.title"),- imagePath: new URL("../../assets/plan-enterprise.png", import.meta.url)- .href,- ruleList: [- ...getRuleListWithLevel(["engine.mysql.use-innodb"], RuleLevel.ERROR),- ...getRuleListWithLevel(- [- "naming.table",- "naming.column",- "naming.index.uk",- "naming.index.fk",- "naming.index.idx",- ],- RuleLevel.WARNING- ),- ...getRuleListWithLevel(- [- "statement.select.no-select-all",- "statement.where.require",- "statement.where.no-leading-wildcard-like",- "table.require-pk",- ],- RuleLevel.ERROR- ),- ...getRuleListWithLevel(- ["column.required", "column.no-null"],- RuleLevel.WARNING- ),- ...getRuleListWithLevel(- ["schema.backward-compatibility"],- RuleLevel.ERROR- ),- ],- },- {- title: t("schema-review-policy.template.policy-for-dev.title"),- imagePath: new URL("../../assets/plan-free.png", import.meta.url).href,- ruleList: [- ...getRuleListWithLevel(["engine.mysql.use-innodb"], RuleLevel.ERROR),- ...getRuleListWithLevel(- [- "naming.table",- "naming.column",- "naming.index.uk",- "naming.index.fk",- "naming.index.idx",- "statement.select.no-select-all",- "statement.where.require",- "statement.where.no-leading-wildcard-like",- ],- RuleLevel.WARNING- ),- ...getRuleListWithLevel(["table.require-pk"], RuleLevel.ERROR),- ...getRuleListWithLevel(- ["column.required", "column.no-null", "schema.backward-compatibility"],- RuleLevel.WARNING- ),- ],- },-];-const BASIC_INFO_STEP = 0;const CONFIGURE_RULE_STEP = 1;const PREVIEW_STEP = 2;diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vueindex 3a3b135fdb..4647892f12 100644--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue@@ -57,7 +57,11 @@class="leading-8">{{- $t(`schema-review-policy.payload-config.${component.title}`)+ $t(+ `schema-review-policy.rule.${getRuleLocalizationKey(+ rule.type+ )}.component.${component.key}.title`+ )}}:<spanv-if="@@ -94,6 +98,7 @@ import { computed } from "vue";import {RuleTemplate,getRuleLocalization,+ getRuleLocalizationKey,convertToCategoryList,Environment,} from "@/types";diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vueindex 115dd22103..f8e9410331 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue@@ -18,8 +18,16 @@"@click="$emit('select', index)">- <img class="h-24" :src="template.imagePath" alt="" />- <span class="text-sm lg:text-base mt-4">{{ template.title }}</span>+ <img class="h-24" :src="getTemplateImage(template.id)" alt="" />+ <span class="text-sm lg:text-base mt-4">+ {{+ $t(+ `schema-review-policy.template.${template.id+ .split(".")+ .join("-")}`+ )+ }}+ </span><heroicons-solid:check-circlev-if="index == selectedTemplateIndex"class="w-7 h-7 text-gray-500 absolute top-3 left-3"@@ -55,4 +63,7 @@ const props = defineProps({});const emit = defineEmits(["select"]);++const getTemplateImage = (id: string) =>+ new URL(`../../../assets/${id}.png`, import.meta.url).href;</script>diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vueindex a77cafbe8c..2e9e5f6bbd 100644--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue@@ -59,7 +59,13 @@class="mb-1"><p class="mb-3">- {{ $t(`schema-review-policy.payload-config.${config.title}`) }}+ {{+ $t(+ `schema-review-policy.rule.${getRuleLocalizationKey(+ selectedRule.type+ )}.component.${config.key}.title`+ )+ }}</p><inputv-if="config.payload.type == 'STRING'"@@ -86,15 +92,22 @@type="text"pattern="[a-z]+"class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full border-gray-300 rounded-md"- :placeholder="- $t('schema-review-policy.payload-config.input-then-press-enter')- "+ :placeholder="$t('schema-review-policy.input-then-press-enter')"@keyup.enter="(e) => pushToList(index, e)"/></div><InputWithTemplatev-else-if="config.payload.type == 'TEMPLATE'"- :template-list="config.payload.templateList"+ :template-list="+ config.payload.templateList.map((id) => ({+ id,+ description: $t(+ `schema-review-policy.rule.${getRuleLocalizationKey(+ selectedRule.type+ )}.component.${config.key}.template.${id}`+ ),+ }))+ ":value="getStringPayload(index)"@change="(val) => (state.payload[index] = val)"/>@@ -111,6 +124,7 @@ import {RuleTemplate,RuleConfigComponent,getRuleLocalization,+ getRuleLocalizationKey,} from "@/types/schemaSystem";type PayloadValueList = (string | string[])[];diff --git a/frontend/src/components/Issue/TaskCheckRunPanel.vue b/frontend/src/components/Issue/TaskCheckRunPanel.vueindex 72142d1084..7efa358723 100644--- a/frontend/src/components/Issue/TaskCheckRunPanel.vue+++ b/frontend/src/components/Issue/TaskCheckRunPanel.vue@@ -60,9 +60,10 @@ import {ErrorCode,ERROR_LIST,GeneralErrorCode,- ruleTemplateList,+ ruleTemplateMap,getRuleLocalization,SchemaReviewPolicyErrorCode,+ RuleType,} from "@/types";const columnList: BBTableColumn[] = [@@ -151,9 +152,7 @@ export default defineComponent({case SchemaReviewPolicyErrorCode.COLUMN_CANBE_NULL:case SchemaReviewPolicyErrorCode.NOT_INNODB_ENGINE:case SchemaReviewPolicyErrorCode.NO_PK_IN_TABLE:- const rule = ruleTemplateList.find(- (r) => r.type === checkResult.title- );+ const rule = ruleTemplateMap.get(checkResult.title as RuleType);if (rule) {const ruleLocalization = getRuleLocalization(rule.type);diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 86e24b175d..b1bdc5a0c3 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1446,13 +1446,10 @@"schema": "Schema"},"template": {- "policy-for-prod": {- "title": "Production Environment Template"- },- "policy-for-dev": {- "title": "Development Environment Template"- }+ "mysql-prod": "Production Environment Template",+ "mysql-dev": "Development Environment Template"},+ "input-then-press-enter": "Input the value then press enter to add","rule": {"engine-mysql-use-innodb": {"title": "Use Innodb",@@ -1464,27 +1461,71 @@},"naming-table": {"title": "Table naming check",- "description": "Enforce the table name format. Default snake_lower_case."+ "description": "Enforce the table name format. Default snake_lower_case.",+ "component": {+ "name_format": {+ "title": "Table name format (regex)"+ }+ }},"naming-column": {"title": "Column naming check",- "description": "Enforce the column name format. Default snake_lower_case."+ "description": "Enforce the column name format. Default snake_lower_case.",+ "component": {+ "name_format": {+ "title": "Column name format (regex)"+ }+ }},"naming-index-uk": {"title": "Unique key naming check",- "description": "Enforce the unique key name format. Default uk_<table_name>_<column_list>."+ "description": "Enforce the unique key name format. Default uk_<table_name>_<column_list>.",+ "component": {+ "name_format": {+ "title": "Unique key name format",+ "template": {+ "table": "The table name",+ "column_list": "Index column names, joined by _"+ }+ }+ }},"naming-index-fk": {"title": "Foreign key naming check",- "description": "Enforce the foreign key name format. Default fk_<referencing_table>_<referencing_column>_<referenced_table>_<referenced_column>."+ "description": "Enforce the foreign key name format. Default fk_<referencing_table>_<referencing_column>_<referenced_table>_<referenced_column>.",+ "component": {+ "name_format": {+ "title": "Foreign key name format",+ "template": {+ "referencing_table": "The referencing table name",+ "referencing_column": "The referencing column name",+ "referenced_table": "The referenced table name",+ "referenced_column": "The referenced column name"+ }+ }+ }},"naming-index-idx": {"title": "Index naming check",- "description": "Enforce the index name format. Default idx_<table_name>_<column_list>."+ "description": "Enforce the index name format. Default idx_<table_name>_<column_list>.",+ "component": {+ "name_format": {+ "title": "Index name format",+ "template": {+ "table": "The table name",+ "column_list": "Index column names, joined by _"+ }+ }+ }},"column-required": {"title": "Required columns",- "description": "Enforce the required columns in each table."+ "description": "Enforce the required columns in each table.",+ "component": {+ "column_list": {+ "title": "Required column names"+ }+ }},"column-no-null": {"title": "Disallow NULL",@@ -1507,23 +1548,6 @@"description": "MySQL and TiDB support checking whether the schema change is backward compatible."}},- "payload-config": {- "table-name-format": "Table name format (regex)",- "column-name-format": "Column name format (regex)",- "uk-name-format": "Unique key name format",- "idx-name-format": "Index name format",- "fk-name-format": "Foreign key name format",- "required-column": "Required column names",- "input-then-press-enter": "Input the value then press enter to add",- "template": {- "table-name": "The table name",- "column-list": "Index column names, joined by _",- "referencing-table": "The referencing table name",- "referencing-column": "The referencing column name",- "referenced-table": "The referenced table name",- "referenced-column": "The referenced column name"- }- },"error-level": {"name": "Error Level","error": "Error",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex b8c756745e..ac3377ac9a 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1447,13 +1447,10 @@"schema": "Schema"},"template": {- "policy-for-prod": {- "title": "针对生产环境的审核策略模板"- },- "policy-for-dev": {- "title": "针对开发环境的审核策略模板"- }+ "mysql-prod": "针对生产环境的审核策略模板",+ "mysql-dev": "针对开发环境的审核策略模板"},+ "input-then-press-enter": "输入后按下回车来添加","rule": {"engine-mysql-use-innodb": {"title": "使用 InnoDB 作为储存引擎",@@ -1465,27 +1462,71 @@},"naming-table": {"title": "表名命名检查",- "description": "限制表名命名风格,默认为小写字母_下划线。"+ "description": "限制表名命名风格,默认为小写字母_下划线。",+ "component": {+ "name_format": {+ "title": "表命名规则(正则)"+ }+ }},"naming-column": {"title": "列名命名检查",- "description": "限制列名命名风格,默认为小写字母_下划线。"+ "description": "限制列名命名风格,默认为小写字母_下划线。",+ "component": {+ "name_format": {+ "title": "列命名规则(正则)"+ }+ }},"naming-index-uk": {"title": "唯一键命名检查",- "description": "限制唯一键命名风格,默认为 uk_<表名>_<主键包含的字段名组合>。"+ "description": "限制唯一键命名风格,默认为 uk_<表名>_<主键包含的字段名组合>。",+ "component": {+ "name_format": {+ "title": "唯一键命名规则",+ "template": {+ "table": "表名",+ "column_list": "索引包含的字段名,通过 _ 连接"+ }+ }+ }},"naming-index-fk": {"title": "外键命名检查",- "description": "限制外键命名风格,默认为 fk_<目标表名>_<目标字段名>_<被引用表名>_<被引用字段名>。"+ "description": "限制外键命名风格,默认为 fk_<目标表名>_<目标字段名>_<被引用表名>_<被引用字段名>。",+ "component": {+ "name_format": {+ "title": "外键命名规则",+ "template": {+ "referencing_table": "目标表名",+ "referencing_column": "目标字段名",+ "referenced_table": "被引用的表名",+ "referenced_column": "被引用的字段名"+ }+ }+ }},"naming-index-idx": {"title": "索引命名检查",- "description": "限制索引命名风格,默认为 idx_<表名>_<索引包含的字段名组合>。"+ "description": "限制索引命名风格,默认为 idx_<表名>_<索引包含的字段名组合>。",+ "component": {+ "name_format": {+ "title": "索引命名规则",+ "template": {+ "table": "表名",+ "column_list": "索引包含的字段名,通过 _ 连接"+ }+ }+ }},"column-required": {"title": "必须包含的字段",- "description": "强制要求表中必须包含某些字段。"+ "description": "强制要求表中必须包含某些字段。",+ "component": {+ "column_list": {+ "title": "必须包含的字段名"+ }+ }},"column-no-null": {"title": "禁止字段为 NULL",@@ -1508,23 +1549,6 @@"description": "MySQL 和 TiDB 支持检测 schema 变更是否向后兼容"}},- "payload-config": {- "table-name-format": "表命名规则(正则)",- "column-name-format": "列命名规则(正则)",- "uk-name-format": "唯一键命名规则",- "idx-name-format": "索引命名规则",- "fk-name-format": "外键命名规则",- "required-column": "必须包含的字段名",- "input-then-press-enter": "输入后按下回车来添加",- "template": {- "table-name": "表名",- "column-list": "索引包含的字段名,通过 _ 连接",- "referencing-table": "目标表名",- "referencing-column": "目标字段名",- "referenced-table": "被引用的表名",- "referenced-column": "被引用的字段名"- }- },"error-level": {"name": "错误等级","error": "错误",diff --git a/frontend/src/types/schemaSystem.ts b/frontend/src/types/schemaSystem.tsindex 9e80239896..39c6836cd7 100644--- a/frontend/src/types/schemaSystem.ts+++ b/frontend/src/types/schemaSystem.ts@@ -3,6 +3,7 @@ import { PolicyId } from "./id";import { Principal } from "./principal";import { RowStatus } from "./common";import { Environment } from "./environment";+import schemaSystemConfig from "./sqlReviewConfig.yaml";// The engine type for rule templateexport type SchemaRuleEngineType = "MYSQL" | "COMMON";@@ -50,15 +51,14 @@ interface StringArrayPayload {interface TemplatePayload {type: "TEMPLATE";default: string;- templateList: { id: string; description?: string }[];+ templateList: string[];value?: string;}// RuleConfigComponent is the rule configuration options and default value.// Used by the frontend.export interface RuleConfigComponent {- title: string;- description: string;+ key: string;payload: StringPayload | TemplatePayload | StringArrayPayload;}@@ -126,242 +126,20 @@ export interface RuleTemplate {// SchemaReviewPolicyTemplate is the rule template setexport interface SchemaReviewPolicyTemplate {- title: string;- imagePath: string;+ id: string;ruleList: RuleTemplate[];}-// RULE_TEMPLATE_PAYLOAD_MAP is the relationship mapping for the rule type and payload.-// Used by frontend to get different rule payload configurations.-export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleConfigComponent[]> =- new Map([- [- "naming.table",- [- {- title: "table-name-format",- description: "",- payload: {- type: "STRING",- default: "^[a-z]+(_[a-z]+)*$",- },- },- ],- ],- [- "naming.column",- [- {- title: "column-name-format",- description: "",- payload: {- type: "STRING",- default: "^[a-z]+(_[a-z]+)*$",- },- },- ],- ],- [- "naming.index.uk",- [- {- title: "uk-name-format",- description: "",- payload: {- type: "TEMPLATE",- default: "^uk_{{table}}_{{column_list}}$",- templateList: [- {- id: "table",- description:- "schema-review-policy.payload-config.template.table-name",- },- {- id: "column_list",- description:- "schema-review-policy.payload-config.template.column-list",- },- ],- },- },- ],- ],- [- "naming.index.fk",- [- {- title: "fk-name-format",- description: "",- payload: {- type: "TEMPLATE",- default:- "^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$",- templateList: [- {- id: "referencing_table",- description:- "schema-review-policy.payload-config.template.referencing-table",- },- {- id: "referencing_column",- description:- "schema-review-policy.payload-config.template.referencing-column",- },- {- id: "referenced_table",- description:- "schema-review-policy.payload-config.template.referenced-table",- },- {- id: "referenced_column",- description:- "schema-review-policy.payload-config.template.referenced-column",- },- ],- },- },- ],- ],- [- "naming.index.idx",- [- {- title: "idx-name-format",- description: "",- payload: {- type: "TEMPLATE",- default: "^idx_{{table}}_{{column_list}}$",- templateList: [- {- id: "table",- description:- "schema-review-policy.payload-config.template.table-name",- },- {- id: "column_list",- description:- "schema-review-policy.payload-config.template.column-list",- },- ],- },- },- ],- ],- [- "column.required",- [- {- title: "required-column",- description: "",- payload: {- type: "STRING_ARRAY",- default: [- "id",- "created_ts",- "updated_ts",- "creator_id",- "updater_id",- ],- },- },- ],- ],- ]);--// ruleTemplateList stores the default value for each rule template-export const ruleTemplateList: RuleTemplate[] = [- {- type: "engine.mysql.use-innodb",- category: "ENGINE",- engine: "MYSQL",- level: RuleLevel.ERROR,- componentList: [],- },- {- type: "table.require-pk",- category: "TABLE",- engine: "COMMON",- level: RuleLevel.ERROR,- componentList: [],- },- {- type: "naming.table",- category: "NAMING",- engine: "COMMON",- componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.table") ?? [],- level: RuleLevel.ERROR,- },- {- type: "naming.column",- category: "NAMING",- engine: "COMMON",- componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.column") ?? [],- level: RuleLevel.ERROR,- },- {- type: "naming.index.uk",- category: "NAMING",- engine: "COMMON",- componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.index.uk") ?? [],- level: RuleLevel.ERROR,- },- {- type: "naming.index.fk",- category: "NAMING",- engine: "COMMON",- componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.index.fk") ?? [],- level: RuleLevel.ERROR,- },- {- type: "naming.index.idx",- category: "NAMING",- engine: "COMMON",- componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.index.idx") ?? [],- level: RuleLevel.ERROR,- },- {- type: "column.required",- category: "COLUMN",- engine: "COMMON",- componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("column.required") ?? [],- level: RuleLevel.ERROR,- },- {- type: "column.no-null",- category: "COLUMN",- engine: "COMMON",- level: RuleLevel.ERROR,- componentList: [],- },- {- type: "statement.select.no-select-all",- category: "STATEMENT",- engine: "COMMON",- level: RuleLevel.ERROR,- componentList: [],- },- {- type: "statement.where.require",- category: "STATEMENT",- engine: "COMMON",- level: RuleLevel.ERROR,- componentList: [],- },- {- type: "statement.where.no-leading-wildcard-like",- category: "STATEMENT",- engine: "COMMON",- level: RuleLevel.ERROR,- componentList: [],- },- {- type: "schema.backward-compatibility",- category: "SCHEMA",- engine: "MYSQL",- level: RuleLevel.ERROR,- componentList: [],- },-];+export const TEMPLATE_LIST =+ schemaSystemConfig.templateList as SchemaReviewPolicyTemplate[];++export const ruleTemplateMap: Map<RuleType, RuleTemplate> =+ TEMPLATE_LIST.reduce((map, template) => {+ for (const rule of template.ruleList) {+ map.set(rule.type, rule);+ }+ return map;+ }, new Map<RuleType, RuleTemplate>());interface RuleCategory {id: CategoryType;@@ -372,14 +150,11 @@ interface RuleCategory {export const convertToCategoryList = (ruleList: RuleTemplate[]): RuleCategory[] => {- const categoryOrder: Map<CategoryType, number> = new Map([- ["ENGINE", 6],- ["NAMING", 5],- ["STATEMENT", 4],- ["TABLE", 3],- ["SCHEMA", 2],- ["COLUMN", 1],- ]);+ const categoryList = schemaSystemConfig.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]) {@@ -519,11 +294,15 @@ export const convertRuleTemplateToPolicyRule = (throw new Error(`Invalid rule ${rule.type}`);};+export const getRuleLocalizationKey = (type: RuleType): string => {+ return type.split(".").join("-");+};+export const getRuleLocalization = (type: RuleType): { title: string; description: string } => {const { t } = useI18n();- const key = type.split(".").join("-");+ const key = getRuleLocalizationKey(type);const title = t(`schema-review-policy.rule.${key}.title`);const description = t(`schema-review-policy.rule.${key}.description`);diff --git a/frontend/src/types/sqlReviewConfig.yaml b/frontend/src/types/sqlReviewConfig.yamlnew file mode 100644index 0000000000..fb8fc15b59--- /dev/null+++ b/frontend/src/types/sqlReviewConfig.yaml@@ -0,0 +1,223 @@+---+categoryList:+ - ENGINE+ - NAMING+ - STATEMENT+ - TABLE+ - SCHEMA+ - COLUMN+templateList:+ - id: mysql.prod+ ruleList:+ - type: engine.mysql.use-innodb+ category: ENGINE+ engine: MYSQL+ level: ERROR+ componentList: []+ - type: table.require-pk+ category: TABLE+ engine: COMMON+ level: ERROR+ componentList: []+ - type: statement.select.no-select-all+ category: STATEMENT+ engine: COMMON+ level: ERROR+ componentList: []+ - type: statement.where.require+ category: STATEMENT+ engine: COMMON+ level: ERROR+ componentList: []+ - type: statement.where.no-leading-wildcard-like+ category: STATEMENT+ engine: COMMON+ level: ERROR+ componentList: []+ - type: naming.table+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: STRING+ default: "^[a-z]+(_[a-z]+)*$"+ level: WARNING+ - type: naming.column+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: STRING+ default: "^[a-z]+(_[a-z]+)*$"+ level: WARNING+ - type: naming.index.uk+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: TEMPLATE+ default: "^uk_{{table}}_{{column_list}}$"+ templateList:+ - table+ - column_list+ level: WARNING+ - type: naming.index.idx+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: TEMPLATE+ default: "^idx_{{table}}_{{column_list}}$"+ templateList:+ - table+ - column_list+ level: WARNING+ - type: naming.index.fk+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: TEMPLATE+ default: "^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$"+ templateList:+ - referencing_table+ - referencing_column+ - referenced_table+ - referenced_column+ level: WARNING+ - type: column.required+ category: COLUMN+ engine: COMMON+ componentList:+ - key: column_list+ payload:+ type: STRING_ARRAY+ default:+ - id+ - created_ts+ - updated_ts+ - creator_id+ - updater_id+ level: WARNING+ - type: column.no-null+ category: COLUMN+ engine: COMMON+ level: WARNING+ componentList: []+ - type: schema.backward-compatibility+ category: SCHEMA+ engine: MYSQL+ level: WARNING+ componentList: []+ - id: mysql.dev+ ruleList:+ - type: engine.mysql.use-innodb+ category: ENGINE+ engine: MYSQL+ level: ERROR+ componentList: []+ - type: table.require-pk+ category: TABLE+ engine: COMMON+ level: ERROR+ componentList: []+ - type: naming.table+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: STRING+ default: "^[a-z]+(_[a-z]+)*$"+ level: WARNING+ - type: naming.column+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: STRING+ default: "^[a-z]+(_[a-z]+)*$"+ level: WARNING+ - type: naming.index.uk+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: TEMPLATE+ default: "^uk_{{table}}_{{column_list}}$"+ templateList:+ - table+ - column_list+ level: WARNING+ - type: naming.index.idx+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: TEMPLATE+ default: "^idx_{{table}}_{{column_list}}$"+ templateList:+ - table+ - column_list+ level: WARNING+ - type: naming.index.fk+ category: NAMING+ engine: COMMON+ componentList:+ - key: name_format+ payload:+ type: TEMPLATE+ default: "^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$"+ templateList:+ - referencing_table+ - referencing_column+ - referenced_table+ - referenced_column+ level: WARNING+ - type: column.required+ category: COLUMN+ engine: COMMON+ componentList:+ - key: column_list+ payload:+ type: STRING_ARRAY+ default:+ - id+ - created_ts+ - updated_ts+ - creator_id+ - updater_id+ level: WARNING+ - type: column.no-null+ category: COLUMN+ engine: COMMON+ level: WARNING+ componentList: []+ - type: statement.select.no-select-all+ category: STATEMENT+ engine: COMMON+ level: WARNING+ componentList: []+ - type: statement.where.require+ category: STATEMENT+ engine: COMMON+ level: WARNING+ componentList: []+ - type: statement.where.no-leading-wildcard-like+ category: STATEMENT+ engine: COMMON+ level: WARNING+ componentList: []+ - type: schema.backward-compatibility+ category: SCHEMA+ engine: MYSQL+ level: WARNING+ componentList: []diff --git a/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue b/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vueindex f5969a2152..fc10d027ee 100644--- a/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue+++ b/frontend/src/views/SettingWorkspaceSchemaReviewDetail.vue@@ -213,7 +213,7 @@ import {DatabaseSchemaReviewPolicy,SchemaRuleEngineType,convertToCategoryList,- ruleTemplateList,+ ruleTemplateMap,convertPolicyRuleToRuleTemplate,} from "@/types";import {@@ -275,11 +275,6 @@ const reviewPolicy = computed((): DatabaseSchemaReviewPolicy => {);});-const ruleMap = ruleTemplateList.reduce((map, rule) => {- map.set(rule.type, rule);- return map;-}, new Map<RuleType, RuleTemplate>());-const selectedRuleList = computed((): RuleTemplate[] => {if (!reviewPolicy.value) {return [];@@ -288,7 +283,7 @@ const selectedRuleList = computed((): RuleTemplate[] => {const ruleTemplateList: RuleTemplate[] = [];for (const policyRule of reviewPolicy.value.ruleList) {- const rule = ruleMap.get(policyRule.type);+ const rule = ruleTemplateMap.get(policyRule.type);if (!rule) {continue;}diff --git a/frontend/src/yaml.d.ts b/frontend/src/yaml.d.tsnew file mode 100644index 0000000000..6383136f48--- /dev/null+++ b/frontend/src/yaml.d.ts@@ -0,0 +1,4 @@+declare module "*.yaml" {+ const data: any;+ export default data;+}diff --git a/frontend/vite.config.ts b/frontend/vite.config.tsindex a8e1f84169..12f88057af 100644--- a/frontend/vite.config.ts+++ b/frontend/vite.config.ts@@ -5,6 +5,7 @@ import VueI18n from "@intlify/vite-plugin-vue-i18n";import Icons from "unplugin-icons/vite";import IconsResolver from "unplugin-icons/resolver";import Components from "unplugin-vue-components/vite";+import yaml from "@rollup/plugin-yaml";const SERVER_PORT = parseInt(process.env.PORT ?? "", 10) ?? 3000;const HTTPS_PORT = 443;@@ -32,6 +33,7 @@ export default defineConfig(() => {],}),Icons(),+ yaml(),],server: {port: SERVER_PORT,