Skip to content

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

chore(sql-review): add some rules in front-end (#3125)

rebelice00bb977731e4
diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.json
index 61afc0d979..b804b00751 100644
--- a/frontend/src/locales/sql-review/en-US.json
+++ b/frontend/src/locales/sql-review/en-US.json
@@ -147,6 +147,18 @@
}
}
},
+ "naming-column-auto-increment": {
+ "title": "Auto-increment column naming check",
+ "description": "Enforce the auto-increment column name format and length limit. Default id within 63 characters.",
+ "component": {
+ "format": {
+ "title": "Auto-increment column name format (regex)"
+ },
+ "maxLength": {
+ "title": "Length limit"
+ }
+ }
+ },
"column-required": {
"title": "Required columns",
"description": "Enforce the required columns in each table.",
@@ -186,7 +198,7 @@
"description": "Disallow changing column order."
},
"column-set-default-for-not-null": {
- "title": "Set default value",
+ "title": "Set default value for NOT NULL column",
"description": "Require default value for not NULL column."
},
"column-auto-increment-must-integer": {
@@ -227,6 +239,14 @@
}
}
},
+ "column-current-time-count-limit": {
+ "title": "Limit the count of current time columns",
+ "description": "Limit the count of NOW(), CURRENT_TIME() and CURRENT_TIMESTAMP() columns."
+ },
+ "column-require-default": {
+ "title": "Require column default value",
+ "description": ""
+ },
"statement-select-no-select-all": {
"title": "Disallow \"SELECT *\"",
"description": "Disallow 'SELECT *' statement."
@@ -272,6 +292,19 @@
}
}
},
+ "statement-affected-row-limit": {
+ "title": "Affected row limit",
+ "description": "Limit the \"DELETE\" and \"UPDATE\" affected row",
+ "component": {
+ "number": {
+ "title": "Maximum affected rows"
+ }
+ }
+ },
+ "statement-dml-dry-run": {
+ "title": "Dry run DML statements",
+ "description": "Dry run DML statements by EXPLAIN."
+ },
"schema-backward-compatibility": {
"title": "Backward compatibility",
"description": "MySQL and TiDB support checking whether the schema change is backward compatible."
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index f4b12117d5..ddd9139206 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -148,6 +148,18 @@
}
}
},
+ "naming-column-auto-increment": {
+ "title": "自增列命名检查",
+ "description": "限制自增列命名风格和长度,默认为 id ,且不超过 63 个字符。",
+ "component": {
+ "format": {
+ "title": "自增列命名规则(正则)"
+ },
+ "maxLength": {
+ "title": "长度限制"
+ }
+ }
+ },
"column-required": {
"title": "必须包含的字段",
"description": "强制要求表中必须包含某些字段。",
@@ -187,7 +199,7 @@
"description": "不允许列的顺序变更。"
},
"column-set-default-for-not-null": {
- "title": "为字段设置默认值",
+ "title": "为 NOT NULL 字段设置默认值",
"description": "不允许为 NULL 的字段必须设定默认值。"
},
"column-auto-increment-must-integer": {
@@ -228,6 +240,14 @@
}
}
},
+ "column-current-time-count-limit": {
+ "title": "限制 NOW() 列的数量",
+ "description": "限制列默认值或 ON UPDATE 值为 NOW(), CURRENT_TIME() 和 CURRENT_TIMESTAMP() 的数量。"
+ },
+ "column-require-default": {
+ "title": "强制设置列默认值",
+ "description": ""
+ },
"statement-select-no-select-all": {
"title": "禁止 \"SELECT *\"",
"description": "不允许使用 \"SELECT *\" 语句。"
@@ -273,6 +293,19 @@
}
}
},
+ "statement-affected-row-limit": {
+ "title": "限制影响行数",
+ "description": "限制 \"DELETE\" and \"UPDATE\" 语句影响的行数。",
+ "component": {
+ "number": {
+ "title": "最大影响行数"
+ }
+ }
+ },
+ "statement-dml-dry-run": {
+ "title": "试运行 DML 语句",
+ "description": "使用 EXPLAIN 语句试运行 DML。"
+ },
"schema-backward-compatibility": {
"title": "向后兼容",
"description": "MySQL 和 TiDB 支持检测 schema 变更是否向后兼容。"
diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yaml
index 38c0ac2928..23021ec503 100644
--- a/frontend/src/types/sql-review-schema.yaml
+++ b/frontend/src/types/sql-review-schema.yaml
@@ -112,7 +112,7 @@ ruleList:
- key: number
payload:
type: NUMBER
- default: 5
+ default: 1000
- type: statement.insert.must-specify-column
category: STATEMENT
engineList:
@@ -125,6 +125,20 @@ ruleList:
- MYSQL
- TIDB
componentList: []
+ - type: statement.affected-row-limit
+ category: STATEMENT
+ engineList:
+ - MYSQL
+ componentList:
+ - key: number
+ payload:
+ type: NUMBER
+ default: 1000
+ - type: statement.dml-dry-run
+ category: STATEMENT
+ engineList:
+ - MYSQL
+ componentList: []
- type: naming.table
category: NAMING
engineList:
@@ -227,6 +241,20 @@ ruleList:
payload:
type: NUMBER
default: 63
+ - type: naming.column.auto-increment
+ category: NAMING
+ engineList:
+ - MYSQL
+ - TIDB
+ componentList:
+ - key: format
+ payload:
+ type: STRING
+ default: "^id$"
+ - key: maxLength
+ payload:
+ type: NUMBER
+ default: 64
- type: column.required
category: COLUMN
engineList:
@@ -319,7 +347,7 @@ ruleList:
- key: number
payload:
type: NUMBER
- default: 5
+ default: 20
- type: column.auto-increment-initial-value
category: COLUMN
engineList:
@@ -336,6 +364,18 @@ ruleList:
- MYSQL
- TIDB
componentList: []
+ - type: column.current-time-count-limit
+ category: COLUMN
+ engineList:
+ - MYSQL
+ - TIDB
+ componentList: []
+ - type: column.require-default
+ category: COLUMN
+ engineList:
+ - MYSQL
+ - TIDB
+ componentList: []
- type: schema.backward-compatibility
category: SCHEMA
engineList:
diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.ts
index 99af9a88b9..e4e3525ed1 100644
--- a/frontend/src/types/sqlReview.ts
+++ b/frontend/src/types/sqlReview.ts
@@ -103,6 +103,7 @@ export type RuleType =
| "naming.index.pk"
| "naming.index.fk"
| "naming.index.idx"
+ | "naming.column.auto-increment"
| "column.required"
| "column.no-null"
| "column.comment"
@@ -116,6 +117,8 @@ export type RuleType =
| "column.auto-increment-must-unsigned"
| "column.maximum-character-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"
@@ -126,6 +129,8 @@ export type RuleType =
| "statement.insert.must-specify-column"
| "statement.insert.disallow-order-by-rand"
| "statement.insert.row-limit"
+ | "statement.affected-row-limit"
+ | "statement.dml-dry-run"
| "schema.backward-compatibility"
| "database.drop-empty-database"
| "system.charset.allowlist"
@@ -356,6 +361,7 @@ export const convertPolicyRuleToRuleTemplate = (
],
};
case "naming.column":
+ case "naming.column.auto-increment":
case "naming.table":
if (!stringComponent || !numberComponent) {
throw new Error(`Invalid rule ${ruleTemplate.type}`);
@@ -489,6 +495,7 @@ export const convertPolicyRuleToRuleTemplate = (
],
};
case "statement.insert.row-limit":
+ case "statement.affected-row-limit":
case "column.maximum-character-length":
case "column.auto-increment-initial-value":
case "index.key-number-limit":
@@ -553,6 +560,7 @@ export const convertRuleTemplateToPolicyRule = (
},
};
case "naming.column":
+ case "naming.column.auto-increment":
case "naming.table":
if (!stringPayload || !numberPayload) {
throw new Error(`Invalid rule ${rule.type}`);
@@ -614,6 +622,7 @@ export const convertRuleTemplateToPolicyRule = (
},
};
case "statement.insert.row-limit":
+ case "statement.affected-row-limit":
case "column.maximum-character-length":
case "column.auto-increment-initial-value":
case "index.key-number-limit":
diff --git a/plugin/advisor/config/sql-review.dev.yaml b/plugin/advisor/config/sql-review.dev.yaml
index 28bd49a876..40f724b1f1 100644
--- a/plugin/advisor/config/sql-review.dev.yaml
+++ b/plugin/advisor/config/sql-review.dev.yaml
@@ -38,7 +38,13 @@ ruleList:
- type: statement.insert.row-limit
level: WARNING
payload:
- number: 5
+ number: 1000
+ - type: statement.affected-row-limit
+ level: WARNING
+ payload:
+ number: 1000
+ - type: statement.dml-dry-run
+ level: WARNING
- type: naming.table
level: WARNING
payload:
@@ -69,6 +75,11 @@ ruleList:
payload:
format: "^$|^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$"
maxLength: 63
+ - type: naming.column.auto-increment
+ level: WARNING
+ payload:
+ format: "^id$"
+ maxLength: 63
- type: column.required
level: WARNING
payload:
@@ -107,11 +118,17 @@ ruleList:
- type: column.maximum-character-length
level: WARNING
payload:
- number: 5
+ number: 20
- type: column.auto-increment-initial-value
level: WARNING
payload:
number: 1
+ - type: column.current-time-count-limit
+ level: WARNING
+ payload:
+ number: 1000
+ - type: column.require-default
+ level: WARNING
- type: schema.backward-compatibility
level: WARNING
- type: database.drop-empty-database
diff --git a/plugin/advisor/config/sql-review.prod.yaml b/plugin/advisor/config/sql-review.prod.yaml
index da704c1b91..d105869a3a 100644
--- a/plugin/advisor/config/sql-review.prod.yaml
+++ b/plugin/advisor/config/sql-review.prod.yaml
@@ -38,7 +38,13 @@ ruleList:
- type: statement.insert.row-limit
level: WARNING
payload:
- number: 5
+ number: 1000
+ - type: statement.affected-row-limit
+ level: WARNING
+ payload:
+ number: 1000
+ - type: statement.dml-dry-run
+ level: WARNING
- type: naming.table
level: WARNING
payload:
@@ -69,6 +75,11 @@ ruleList:
payload:
format: "^$|^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$"
maxLength: 63
+ - type: naming.column.auto-increment
+ level: WARNING
+ payload:
+ format: "^id$"
+ maxLength: 63
- type: column.required
level: WARNING
payload:
@@ -107,11 +118,17 @@ ruleList:
- type: column.maximum-character-length
level: WARNING
payload:
- number: 5
+ number: 20
- type: column.auto-increment-initial-value
level: WARNING
payload:
number: 1
+ - type: column.current-time-count-limit
+ level: WARNING
+ payload:
+ number: 1000
+ - type: column.require-default
+ level: WARNING
- type: schema.backward-compatibility
level: WARNING
- type: database.drop-empty-database