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(sql-review): update SQL review rules (part 1) (#3055)
ecmadao7f4a38a863e3
diff --git a/frontend/src/components/SQLReview/SQLReviewConfig.vue b/frontend/src/components/SQLReview/SQLReviewConfig.vueindex c4b474380e..6528201669 100644--- a/frontend/src/components/SQLReview/SQLReviewConfig.vue+++ b/frontend/src/components/SQLReview/SQLReviewConfig.vue@@ -11,7 +11,7 @@/><div v-if="selectedRuleList.length > 0" class="mb-5"><div- class="flex cursor-pointer items-center px-2 text-indigo-500"+ class="flex cursor-pointer items-center text-indigo-500"@click="state.openTemplate = !state.openTemplate"><heroicons-solid:chevron-right@@ -32,38 +32,47 @@/></div><div- :class="selectedRuleList.length > 0 ? 'border-b-1 border-gray-200' : ''"+ :class="[+ 'space-y-5',+ selectedRuleList.length > 0 ? 'border-b-1 border-gray-200' : '',+ ]">- <ul role="list" class="divide-y divide-gray-200">- <li v-for="rule in selectedRuleList" :key="rule.type">- <SQLRuleConfig- :selected-rule="rule"- :active="rule.type === state.activeRuleType"- :disabled="- !ruleIsAvailableInSubscription(- rule.type,- subscriptionStore.currentPlan- )- "- @activate="onRuleActivate"- @level-change="(level) => onLevelChange(rule, level)"- @payload-change="(val) => onPayloadChange(rule, val)"- />- </li>- </ul>+ <div v-for="(category, index) in categoryList" :key="index">+ <div class="block text-2xl text-indigo-600 font-semibold px-2 mb-3">+ {{ $t(`sql-review.category.${category.id.toLowerCase()}`) }}+ </div>+ <ul role="list" class="divide-y divide-gray-200">+ <li v-for="rule in category.ruleList" :key="rule.type">+ <SQLRuleConfig+ :selected-rule="rule"+ :active="rule.type === state.activeRuleType"+ :disabled="+ !ruleIsAvailableInSubscription(+ rule.type,+ subscriptionStore.currentPlan+ )+ "+ @activate="onRuleActivate"+ @level-change="(level) => onLevelChange(rule, level)"+ @payload-change="(val) => onPayloadChange(rule, val)"+ />+ </li>+ </ul>+ </div></div></div></div></template><script lang="ts" setup>-import { PropType, reactive } from "vue";+import { PropType, reactive, computed } from "vue";import {RuleType,RuleLevel,RuleTemplate,RuleConfigComponent,SQLReviewPolicyTemplate,+ convertToCategoryList,ruleIsAvailableInSubscription,} from "@/types/sqlReview";import { useSubscriptionStore } from "@/store";@@ -73,7 +82,7 @@ interface LocalState {openTemplate: boolean;}-defineProps({+const props = defineProps({selectedRuleList: {required: true,type: Object as PropType<RuleTemplate[]>,@@ -97,6 +106,10 @@ const state = reactive<LocalState>({openTemplate: false,});+const categoryList = computed(() => {+ return convertToCategoryList(props.selectedRuleList);+});+const onTemplateApply = (index: number) => {emit("apply-template", index);state.activeRuleType = null;diff --git a/frontend/src/components/SQLReview/components/SQLRuleConfig.vue b/frontend/src/components/SQLReview/components/SQLRuleConfig.vueindex 0823805d7d..d4ed9d10d2 100644--- a/frontend/src/components/SQLReview/components/SQLRuleConfig.vue+++ b/frontend/src/components/SQLReview/components/SQLRuleConfig.vue@@ -6,55 +6,57 @@@click="$emit('activate', selectedRule.type)"><div class="flex-1 flex flex-col">- <div class="flex mb-2 items-center space-x-2">+ <div class="flex items-center">+ <div class="flex flex-1 items-center space-x-2">+ <h1 class="flex text-base gap-x-1">+ <NTooltip v-if="disabled" trigger="hover" :show-arrow="false">+ <template #trigger>+ <div class="flex justify-center">+ <heroicons-outline:exclamation+ class="h-6 w-6 text-yellow-600"+ />+ </div>+ </template>+ <span class="whitespace-nowrap">+ {{+ $t("sql-review.not-available-for-free", {+ plan: $t(+ `subscription.plan.${planTypeToString(+ subscriptionStore.currentPlan+ )}.title`+ ),+ })+ }}+ </span>+ </NTooltip>+ {{ getRuleLocalization(selectedRule.type).title }}+ </h1>+ <SQLRuleLevelBadge :level="selectedRule.level" />+ <img+ v-for="engine in selectedRule.engineList"+ :key="engine"+ class="h-4 w-auto"+ :src="getEngineIcon(engine)"+ />+ <a+ :href="`https://www.bytebase.com/docs/sql-review/review-rules/supported-rules#${selectedRule.type}`"+ target="__blank"+ class="flex flex-row space-x-2 items-center text-base text-gray-500 hover:text-gray-900"+ >+ <heroicons-outline:external-link class="w-4 h-4" />+ </a>+ </div><heroicons-solid:chevron-right- class="w-5 h-5 transform transition-all"+ class="w-5 h-5 transform transition-all order-last":class="active ? 'rotate-90' : ''"/>- <h1 class="flex text-base font-semibold text-gray-900 gap-x-1">- <NTooltip v-if="disabled" trigger="hover" :show-arrow="false">- <template #trigger>- <div class="flex justify-center">- <heroicons-outline:exclamation- class="h-6 w-6 text-yellow-600"- />- </div>- </template>- <span class="whitespace-nowrap">- {{- $t("sql-review.not-available-for-free", {- plan: $t(- `subscription.plan.${planTypeToString(- subscriptionStore.currentPlan- )}.title`- ),- })- }}- </span>- </NTooltip>- {{ getRuleLocalization(selectedRule.type).title }}- </h1>- <SQLRuleLevelBadge :level="selectedRule.level" />- <img- v-for="engine in selectedRule.engineList"- :key="engine"- class="h-4 w-auto"- :src="getEngineIcon(engine)"- />- <a- :href="`https://www.bytebase.com/docs/sql-review/review-rules/supported-rules#${selectedRule.type}`"- target="__blank"- class="flex flex-row space-x-2 items-center text-base text-gray-500 hover:text-gray-900"- >- <heroicons-outline:external-link class="w-4 h-4" />- </a></div>- <div class="text-sm text-gray-400 ml-7">+ <div class="text-sm text-gray-400">{{ getRuleLocalization(selectedRule.type).description }}</div></div></div>- <div v-if="active" class="px-10 py-5 text-sm">+ <div v-if="active" class="px-5 py-5 text-sm"><div class="mb-7"><p class="mb-3">{{ $t("sql-review.level.name") }}</p><div class="flex gap-x-3">diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.jsonindex e581c8bef0..8241b8ac1a 100644--- a/frontend/src/locales/sql-review/en-US.json+++ b/frontend/src/locales/sql-review/en-US.json@@ -11,7 +11,8 @@"table": "Table","column": "Column","schema": "Schema",- "database": "Database"+ "database": "Database",+ "index": "Index"},"template": {"bb-sql-review-prod": "Template for Prod Environment",@@ -39,6 +40,10 @@}}},+ "table-disallow-partition": {+ "title": "Disallow partition",+ "description": ""+ },"naming-table": {"title": "Table naming check","description": "Enforce the table name format and length limit. Default snake_lower_case with 63 characters.",@@ -142,6 +147,34 @@"title": "Disallow NULL","description": "Columns cannot have NULL value."},+ "column-disallow-set-charset": {+ "title": "Disallow set charset",+ "description": "Disallow set charset for column."+ },+ "column-disallow-change-type": {+ "title": "Disallow changing type",+ "description": "Disallow change column type."+ },+ "column-disallow-change": {+ "title": "Disallow \"CHANGE COLUMN\" statement",+ "description": ""+ },+ "column-disallow-changing-order": {+ "title": "Disallow changing order",+ "description": "Disallow changing column order."+ },+ "column-set-default-for-not-null": {+ "title": "Set default value",+ "description": "Require default value for not NULL column."+ },+ "column-auto-increment-must-integer": {+ "title": "Use integer for auto-increment column",+ "description": "Auto-increment column requires integer type."+ },+ "column-auto-increment-must-unsigned": {+ "title": "Set unsigned attribute on auto-increment column",+ "description": "Auto-increment column must be the UNSIGNED type."+ },"statement-select-no-select-all": {"title": "Disallow \"SELECT *\"","description": "Disallow 'SELECT *' statement."@@ -158,6 +191,26 @@"title": "Disallow commit","description": "Disallow using commit in the issue."},+ "statement-disallow-limit": {+ "title": "Disallow \"LIMIT\"",+ "description": "Disallow \"LIMIT\" for \"INSERT\", \"UPDATE\", \"DELETE\" statement."+ },+ "statement-disallow-order-by": {+ "title": "Disallow \"ORDER BY\"",+ "description": "Disallow \"ORDER BY\" for \"UPDATE\", \"DELETE\" statement."+ },+ "statement-merge-alter-table": {+ "title": "Merge \"ALTER TABLE\"",+ "description": "Disallow using multiply \"ALTER TABLE\" statement for same table."+ },+ "statement-insert-must-specify-column": {+ "title": "\"INSERT\" statement must specify column",+ "description": "Must specify the column to insert. For example, \"INSERT INTO t (id,name) VALUES(...)\"."+ },+ "statement-insert-disallow-order-by-rand": {+ "title": "Disallow \"ORDER BY rand()\" statement",+ "description": ""+ },"schema-backward-compatibility": {"title": "Backward compatibility","description": "MySQL and TiDB support checking whether the schema change is backward compatible."@@ -165,6 +218,14 @@"database-drop-empty-database": {"title": "Drop database restriction","description": "Can only drop the database if there's no table in it."+ },+ "index-no-duplicate-column": {+ "title": "Disallow duplicate column",+ "description": ""+ },+ "index-type-no-blob": {+ "title": "Disallow BLOB",+ "description": "Disallow using BLOB type column in index."}},"level": {diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.jsonindex 5ef6a70c5d..92083e2506 100644--- a/frontend/src/locales/sql-review/zh-CN.json+++ b/frontend/src/locales/sql-review/zh-CN.json@@ -11,7 +11,9 @@"table": "表","column": "列","schema": "Schema",- "database": "数据库"+ "database": "数据库",+ "index": "索引",+ "insert": "插入"},"template": {"bb-sql-review-prod": "针对生产环境的审核策略模板",@@ -39,6 +41,10 @@}}},+ "table-disallow-partition": {+ "title": "禁止分区",+ "description": ""+ },"naming-table": {"title": "表名命名检查","description": "限制表名命名风格和长度,默认为小写字母_下划线,且不超过 63 个字符。",@@ -142,13 +148,41 @@"title": "禁止字段为 NULL","description": "表中的字段不允许存在 NULL 值。"},+ "column-disallow-set-charset": {+ "title": "禁止设置字符集",+ "description": "禁止为字段设置字符集。"+ },+ "column-disallow-change-type": {+ "title": "禁止改变类型",+ "description": "不允许改变字段的类型。"+ },+ "column-disallow-change": {+ "title": "禁止改变字段",+ "description": "不允许 \"CHANGE COLUMN\" 语句。"+ },+ "column-disallow-changing-order": {+ "title": "禁止改变字段顺序",+ "description": "不允许列的顺序变更。"+ },+ "column-set-default-for-not-null": {+ "title": "为字段设置默认值",+ "description": "不允许为 NULL 的字段必须设定默认值。"+ },+ "column-auto-increment-must-integer": {+ "title": "自增字段必须为数字类型",+ "description": ""+ },+ "column-auto-increment-must-unsigned": {+ "title": "自增列需要设置无符号",+ "description": ""+ },"statement-select-no-select-all": {"title": "禁止 \"SELECT *\"",- "description": "不允许使用 \"SELECT *\" 语句"+ "description": "不允许使用 \"SELECT *\" 语句。"},"statement-where-require": {"title": "强制 \"WHERE\"",- "description": "必须使用 \"WHERE\" 语句"+ "description": "必须使用 \"WHERE\" 语句。"},"statement-where-no-leading-wildcard-like": {"title": "禁止左模糊",@@ -158,13 +192,41 @@"title": "禁止使用提交","description": "禁止在工单中使用提交。"},+ "statement-disallow-limit": {+ "title": "不允许使用 \"LIMIT\"",+ "description": "在 INSERT, UPDATE, DELETE 语句中禁止使用 \"LIMIT\"。"+ },+ "statement-disallow-order-by": {+ "title": "不允许使用 \"ORDER BY\"",+ "description": "在 UPDATE, DELETE 语句中禁止使用 \"ORDER BY\"。"+ },+ "statement-merge-alter-table": {+ "title": "合并 \"ALTER TABLE\" 语句",+ "description": "禁止在工单中对同一张表使用多个 \"ALTER TABLE\" 语句。"+ },+ "statement-insert-must-specify-column": {+ "title": "\"INSERT\" 语句必须指定字段",+ "description": "必须指定插入的字段,也就是要写入哪些列,如 \"INSERT INTO t (id,name) VALUES(...)\"。"+ },+ "statement-insert-disallow-order-by-rand": {+ "title": "不能有 \"ORDER BY rand()\" 语句",+ "description": ""+ },"schema-backward-compatibility": {"title": "向后兼容",- "description": "MySQL 和 TiDB 支持检测 schema 变更是否向后兼容"+ "description": "MySQL 和 TiDB 支持检测 schema 变更是否向后兼容。"},"database-drop-empty-database": {"title": "数据库删除限制","description": "只有当数据库内没有表时,才可以被删除。"+ },+ "index-no-duplicate-column": {+ "title": "索引中的列不能重复",+ "description": ""+ },+ "index-type-no-blob": {+ "title": "BLOB 列不能建作为索引",+ "description": ""}},"level": {diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yamlindex 7a9c54898b..052a643226 100644--- a/frontend/src/types/sql-review-schema.yaml+++ b/frontend/src/types/sql-review-schema.yaml@@ -1,5 +1,6 @@categoryList:- ENGINE+ - INDEX- NAMING- STATEMENT- TABLE@@ -36,6 +37,13 @@ ruleList:payload:type: STRINGdefault: _del$+ # TODO: - type: table.comment+ - type: table.disallow-partition+ category: TABLE+ engineList:+ - MYSQL+ - TIDB+ componentList: []- type: statement.select.no-select-allcategory: STATEMENTengineList:@@ -63,6 +71,37 @@ ruleList:- MYSQL- TIDBcomponentList: []+ - type: statement.disallow-limit+ category: STATEMENT+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ - type: statement.disallow-order-by+ category: STATEMENT+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ - tpye: statement.merge-alter-table+ category: STATEMENT+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ # TODO: - type: statement.insert.row-limit+ - type: statement.insert.must-specify-column+ category: INSERT+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ - type: statement.insert.disallow-order-by-rand+ category: INSERT+ engineList:+ - MYSQL+ - TIDB+ componentList: []- type: naming.tablecategory: NAMINGengineList:@@ -188,6 +227,52 @@ ruleList:- TIDB- POSTGREScomponentList: []+ - type: column.disallow-change-type+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ - type: column.set-default-for-not-null+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ - type: column.disallow-change+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ - type: column.disallow-changing-order+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ # TODO: - type: column.comment+ - type: column.auto-increment-must-integer+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ # TODO: - type: column.type-restriction+ - type: column.disallow-set-charset+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ # TODO: - type: column.maximum-character-length+ # TODO: - type: column.auto-increment-initial-value+ - type: column.auto-increment-must-unsigned+ category: COLUMN+ engineList:+ - MYSQL+ - TIDB+ componentList: []- type: schema.backward-compatibilitycategory: SCHEMAengineList:@@ -201,3 +286,20 @@ ruleList:- MYSQL- TIDBcomponentList: []+ - type: index.no-duplicate-column+ category: INDEX+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ # TODO: - type: index.key-number-limit+ # TODO: - type: index.pk-type+ - type: index.type-no-blob+ category: INDEX+ engineList:+ - MYSQL+ - TIDB+ componentList: []+ # TODO: - type: index.total-number-limit+ # TODO: - type: charset.allowlist+ # TODO: - type: collation.allowlistdiff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.tsindex 7d74a5807e..809f3ff460 100644--- a/frontend/src/types/sqlReview.ts+++ b/frontend/src/types/sqlReview.ts@@ -19,7 +19,8 @@ export type CategoryType =| "TABLE"| "COLUMN"| "SCHEMA"- | "DATABASE";+ | "DATABASE"+ | "INDEX";// The rule levelexport enum RuleLevel {diff --git a/plugin/advisor/config/sql-review.dev.yaml b/plugin/advisor/config/sql-review.dev.yamlindex 04b62d4004..8a146dd891 100644--- a/plugin/advisor/config/sql-review.dev.yaml+++ b/plugin/advisor/config/sql-review.dev.yaml@@ -10,6 +10,8 @@ ruleList:level: ERRORpayload:format: _del$+ - type: table.disallow-partition+ level: ERROR- type: statement.select.no-select-alllevel: WARNING- type: statement.where.require@@ -18,6 +20,16 @@ ruleList:level: WARNING- type: statement.disallow-commitlevel: WARNING+ - type: statement.disallow-limit+ level: WARNING+ - type: statement.disallow-order-by+ level: WARNING+ - type: statement.merge-alter-table+ level: WARNING+ - type: statement.insert.must-specify-column+ level: WARNING+ - type: statement.insert.disallow-order-by-rand+ level: WARNING- type: naming.tablelevel: WARNINGpayload:@@ -59,7 +71,25 @@ ruleList:- updater_id- type: column.no-nulllevel: WARNING+ - type: column.disallow-change-type+ level: ERROR+ - type: column.set-default-for-not-null+ level: ERROR+ - type: column.disallow-change+ level: ERROR+ - type: column.disallow-changing-order+ level: ERROR+ - type: column.auto-increment-must-integer+ level: ERROR+ - type: column.disallow-set-charset+ level: ERROR+ - type: column.auto-increment-must-unsigned+ level: ERROR- type: schema.backward-compatibilitylevel: WARNING- type: database.drop-empty-databaselevel: ERROR+ - type: index.no-duplicate-column+ level: ERROR+ - type: index.type-no-blob+ level: ERRORdiff --git a/plugin/advisor/config/sql-review.prod.yaml b/plugin/advisor/config/sql-review.prod.yamlindex e189ea6f5c..b9278edcb3 100644--- a/plugin/advisor/config/sql-review.prod.yaml+++ b/plugin/advisor/config/sql-review.prod.yaml@@ -10,6 +10,8 @@ ruleList:level: ERRORpayload:format: _del$+ - type: table.disallow-partition+ level: ERROR- type: statement.select.no-select-alllevel: ERROR- type: statement.where.require@@ -18,6 +20,16 @@ ruleList:level: ERROR- type: statement.disallow-commitlevel: ERROR+ - type: statement.disallow-limit+ level: ERROR+ - type: statement.disallow-order-by+ level: ERROR+ - type: statement.merge-alter-table+ level: ERROR+ - type: statement.insert.must-specify-column+ level: ERROR+ - type: statement.insert.disallow-order-by-rand+ level: ERROR- type: naming.tablelevel: WARNINGpayload:@@ -59,7 +71,25 @@ ruleList:- updater_id- type: column.no-nulllevel: WARNING+ - type: column.disallow-change-type+ level: ERROR+ - type: column.set-default-for-not-null+ level: ERROR+ - type: column.disallow-change+ level: ERROR+ - type: column.disallow-changing-order+ level: ERROR+ - type: column.auto-increment-must-integer+ level: ERROR+ - type: column.disallow-set-charset+ level: ERROR+ - type: column.auto-increment-must-unsigned+ level: ERROR- type: schema.backward-compatibilitylevel: WARNING- type: database.drop-empty-databaselevel: ERROR+ - type: index.no-duplicate-column+ level: ERROR+ - type: index.type-no-blob+ level: ERRORdiff --git a/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.go b/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.goindex b767c50a3f..1addd0a47a 100644--- a/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.go+++ b/plugin/advisor/mysql/advisor_insert_disallow_order_by_rand_test.go@@ -27,7 +27,7 @@ func TestInsertDisallowOrderByRand(t *testing.T) {{Status: advisor.Warn,Code: advisor.InsertUseOrderByRand,- Title: "insert.disallow-order-by-rand",+ Title: "statement.insert.disallow-order-by-rand",Content: "\"INSERT INTO tech_book SELECT * FROM tech_book ORDER BY rand()\" uses ORDER BY RAND in the INSERT statement",Line: 1,},@@ -36,7 +36,7 @@ func TestInsertDisallowOrderByRand(t *testing.T) {}advisor.RunSQLReviewRuleTests(t, tests, &InsertDisallowOrderByRandAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleInsertDisallowOrderByRand,+ Type: advisor.SchemaRuleStatementInsertDisallowOrderByRand,Level: advisor.SchemaRuleLevelWarning,Payload: "",}, advisor.MockMySQLDatabase)diff --git a/plugin/advisor/mysql/advisor_insert_must_specify_column_test.go b/plugin/advisor/mysql/advisor_insert_must_specify_column_test.goindex 415a0a936d..8d08944f52 100644--- a/plugin/advisor/mysql/advisor_insert_must_specify_column_test.go+++ b/plugin/advisor/mysql/advisor_insert_must_specify_column_test.go@@ -27,7 +27,7 @@ func TestInsertMustSpecifyColumn(t *testing.T) {{Status: advisor.Warn,Code: advisor.InsertNotSpecifyColumn,- Title: "insert.must-specify-column",+ Title: "statement.insert.must-specify-column",Content: "The INSERT statement must specify columns but \"INSERT INTO tech_book VALUES (1, '1')\" does not",Line: 1,},@@ -36,7 +36,7 @@ func TestInsertMustSpecifyColumn(t *testing.T) {}advisor.RunSQLReviewRuleTests(t, tests, &InsertMustSpecifyColumnAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleInsertMustSpecifyColumn,+ Type: advisor.SchemaRuleStatementInsertMustSpecifyColumn,Level: advisor.SchemaRuleLevelWarning,Payload: "",}, advisor.MockMySQLDatabase)diff --git a/plugin/advisor/mysql/advisor_insert_row_limit_test.go b/plugin/advisor/mysql/advisor_insert_row_limit_test.goindex 5139ec5ea5..27ad820da8 100644--- a/plugin/advisor/mysql/advisor_insert_row_limit_test.go+++ b/plugin/advisor/mysql/advisor_insert_row_limit_test.go@@ -30,7 +30,7 @@ func TestInsertRowLimit(t *testing.T) {{Status: advisor.Warn,Code: advisor.InsertTooManyRows,- Title: "insert.row-limit",+ Title: "statement.insert.row-limit",Content: "The value rows in one INSERT statement should be no more than 5, but found 6",Line: 1,},@@ -42,7 +42,7 @@ func TestInsertRowLimit(t *testing.T) {})require.NoError(t, err)advisor.RunSQLReviewRuleTests(t, tests, &InsertRowLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleInsertRowLimit,+ Type: advisor.SchemaRuleStatementInsertRowLimit,Level: advisor.SchemaRuleLevelWarning,Payload: string(payload),}, advisor.MockMySQLDatabase)diff --git a/plugin/advisor/pg/advisor_insert_row_limit_test.go b/plugin/advisor/pg/advisor_insert_row_limit_test.goindex 0066fd6feb..05e6b162a6 100644--- a/plugin/advisor/pg/advisor_insert_row_limit_test.go+++ b/plugin/advisor/pg/advisor_insert_row_limit_test.go@@ -30,7 +30,7 @@ func TestInsertRowLimit(t *testing.T) {{Status: advisor.Warn,Code: advisor.InsertTooManyRows,- Title: "insert.row-limit",+ Title: "statement.insert.row-limit",Content: "The value rows in \"INSERT INTO tech_book values(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')\" should be no more than 5, but found 6",Line: 1,},@@ -42,7 +42,7 @@ func TestInsertRowLimit(t *testing.T) {})require.NoError(t, err)advisor.RunSQLReviewRuleTests(t, tests, &InsertRowLimitAdvisor{}, &advisor.SQLReviewRule{- Type: advisor.SchemaRuleInsertRowLimit,+ Type: advisor.SchemaRuleStatementInsertRowLimit,Level: advisor.SchemaRuleLevelWarning,Payload: string(payload),}, advisor.MockPostgreSQLDatabase)diff --git a/plugin/advisor/sql_review.go b/plugin/advisor/sql_review.goindex 88001a9566..6e02a3d1cb 100644--- a/plugin/advisor/sql_review.go+++ b/plugin/advisor/sql_review.go@@ -65,6 +65,12 @@ const (SchemaRuleStatementDisallowOrderBy SQLReviewRuleType = "statement.disallow-order-by"// SchemaRuleStatementMergeAlterTable disallow redundant ALTER TABLE statements.SchemaRuleStatementMergeAlterTable SQLReviewRuleType = "statement.merge-alter-table"+ // SchemaRuleStatementInsertRowLimit enforce the insert row limit.+ SchemaRuleStatementInsertRowLimit SQLReviewRuleType = "statement.insert.row-limit"+ // SchemaRuleStatementInsertMustSpecifyColumn enforce the insert column specified.+ SchemaRuleStatementInsertMustSpecifyColumn SQLReviewRuleType = "statement.insert.must-specify-column"+ // SchemaRuleStatementInsertDisallowOrderByRand disallow the order by rand in the INSERT statement.+ SchemaRuleStatementInsertDisallowOrderByRand SQLReviewRuleType = "statement.insert.disallow-order-by-rand"// SchemaRuleTableRequirePK require the table to have a primary key.SchemaRuleTableRequirePK SQLReviewRuleType = "table.require-pk"@@ -129,13 +135,6 @@ const (// SchemaRuleCollationAllowlist enforce the collation allowlist.SchemaRuleCollationAllowlist SQLReviewRuleType = "collation.allowlist"- // SchemaRuleInsertRowLimit enforce the insert row limit.- SchemaRuleInsertRowLimit SQLReviewRuleType = "insert.row-limit"- // SchemaRuleInsertMustSpecifyColumn enforce the insert column specified.- SchemaRuleInsertMustSpecifyColumn SQLReviewRuleType = "insert.must-specify-column"- // SchemaRuleInsertDisallowOrderByRand disallow the order by rand in the INSERT statement.- SchemaRuleInsertDisallowOrderByRand SQLReviewRuleType = "insert.disallow-order-by-rand"-// SchemaRuleCommentLength limit comment length.SchemaRuleCommentLength SQLReviewRuleType = "comment.length"@@ -231,7 +230,7 @@ func (rule *SQLReviewRule) Validate() error {if _, err := UnmarshalCommentConventionRulePayload(rule.Payload); err != nil {return err}- case SchemaRuleIndexKeyNumberLimit, SchemaRuleInsertRowLimit, SchemaRuleIndexTotalNumberLimit, SchemaRuleColumnMaximumCharacterLength, SchemaRuleColumnAutoIncrementInitialValue:+ case SchemaRuleIndexKeyNumberLimit, SchemaRuleStatementInsertRowLimit, SchemaRuleIndexTotalNumberLimit, SchemaRuleColumnMaximumCharacterLength, SchemaRuleColumnAutoIncrementInitialValue:if _, err := UnmarshalNumberTypeRulePayload(rule.Payload); err != nil {return err}@@ -832,17 +831,19 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine db.Type) (Type, errcase db.MySQL, db.TiDB:return MySQLIndexTypeNoBlob, nil}- case SchemaRuleInsertRowLimit:+ case SchemaRuleStatementInsertRowLimit:switch engine {case db.MySQL, db.TiDB:return MySQLInsertRowLimit, nil+ case db.Postgres:+ return PostgreSQLInsertRowLimit, nil}- case SchemaRuleInsertMustSpecifyColumn:+ case SchemaRuleStatementInsertMustSpecifyColumn:switch engine {case db.MySQL, db.TiDB:return MySQLInsertMustSpecifyColumn, nil}- case SchemaRuleInsertDisallowOrderByRand:+ case SchemaRuleStatementInsertDisallowOrderByRand:switch engine {case db.MySQL, db.TiDB:return MySQLInsertDisallowOrderByRand, nil