Skip to content

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

chore: review policy update (#1156)

ecmadao6f889931b613
diff --git a/api/schema_system.go b/api/schema_system.go
index 25e836da06..2c73a6d5dc 100644
--- a/api/schema_system.go
+++ b/api/schema_system.go
@@ -25,15 +25,17 @@ const (
SchemaRulePKNaming SchemaReviewRuleType = "naming.index.pk"
// SchemaRuleUKNaming enforce the unique key name format.
SchemaRuleUKNaming SchemaReviewRuleType = "naming.index.uk"
+ // SchemaRuleFKNaming enforce the foreign key name format.
+ SchemaRuleFKNaming SchemaReviewRuleType = "naming.index.fk"
// SchemaRuleIDXNaming enforce the index name format.
SchemaRuleIDXNaming SchemaReviewRuleType = "naming.index.idx"
- // SchemaRuleQueryNoSelectAll disallow 'SELECT *'.
- SchemaRuleQueryNoSelectAll SchemaReviewRuleType = "query.select.no-select-all"
- // SchemaRuleQueryRequireWhere require 'WHERE' clause.
- SchemaRuleQueryRequireWhere SchemaReviewRuleType = "query.where.require"
- // SchemaRuleQueryNoLeadingWildcardLike disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed.
- SchemaRuleQueryNoLeadingWildcardLike SchemaReviewRuleType = "query.where.no-leading-wildcard-like"
+ // SchemaRuleStatementNoSelectAll disallow 'SELECT *'.
+ SchemaRuleStatementNoSelectAll SchemaReviewRuleType = "statement.select.no-select-all"
+ // SchemaRuleStatementRequireWhere require 'WHERE' clause.
+ SchemaRuleStatementRequireWhere SchemaReviewRuleType = "statement.where.require"
+ // SchemaRuleStatementNoLeadingWildcardLike disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed.
+ SchemaRuleStatementNoLeadingWildcardLike SchemaReviewRuleType = "statement.where.no-leading-wildcard-like"
// SchemaRuleTableRequirePK require the table to have a primary key.
SchemaRuleTableRequirePK SchemaReviewRuleType = "table.require-pk"
diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue
index 035df5b10b..d6ac083c81 100644
--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue
+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewConfig.vue
@@ -51,7 +51,7 @@ import {
RuleType,
RuleLevel,
RuleTemplate,
- RuleTemplatePayload,
+ RuleConfigComponent,
SchemaReviewPolicyTemplate,
} from "@/types/schemaSystem";
@@ -125,7 +125,7 @@ const onPayloadChange = (rule: RuleTemplate, data: (string | string[])[]) => {
break;
}
return list;
- }, [] as RuleTemplatePayload[]),
+ }, [] as RuleConfigComponent[]),
};
emit("change", newRule);
diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue
index 04873934ad..e2964add88 100644
--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue
+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewCreation.vue
@@ -145,10 +145,9 @@ const getRuleListWithLevel = (
}, [] as RuleTemplate[]);
};
-// TODO: i18n
const TEMPLATE_LIST: SchemaReviewPolicyTemplate[] = [
{
- name: "Schema review for Prod",
+ title: t("schema-review-policy.template.policy-for-prod.title"),
imagePath: new URL("../../assets/plan-enterprise.png", import.meta.url)
.href,
ruleList: [
@@ -159,15 +158,16 @@ const TEMPLATE_LIST: SchemaReviewPolicyTemplate[] = [
"naming.column",
"naming.index.pk",
"naming.index.uk",
+ "naming.index.fk",
"naming.index.idx",
],
RuleLevel.WARNING
),
...getRuleListWithLevel(
[
- "query.select.no-select-all",
- "query.where.require",
- "query.where.no-leading-wildcard-like",
+ "statement.select.no-select-all",
+ "statement.where.require",
+ "statement.where.no-leading-wildcard-like",
"table.require-pk",
],
RuleLevel.ERROR
@@ -179,7 +179,7 @@ const TEMPLATE_LIST: SchemaReviewPolicyTemplate[] = [
],
},
{
- name: "Schema review for Dev",
+ 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),
@@ -189,10 +189,11 @@ const TEMPLATE_LIST: SchemaReviewPolicyTemplate[] = [
"naming.column",
"naming.index.pk",
"naming.index.uk",
+ "naming.index.fk",
"naming.index.idx",
- "query.select.no-select-all",
- "query.where.require",
- "query.where.no-leading-wildcard-like",
+ "statement.select.no-select-all",
+ "statement.where.require",
+ "statement.where.no-leading-wildcard-like",
],
RuleLevel.WARNING
),
diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue
index 8adf10de12..d9f9780345 100644
--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue
+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewInfo.vue
@@ -10,7 +10,9 @@
</p>
<BBTextField
class="mt-2 w-full"
- placeholder="Database review name"
+ :placeholder="
+ $t('schema-review-policy.create.basic-info.display-name-placeholder')
+ "
:value="name"
@input="(e) => onNameChange(e)"
/>
diff --git a/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue b/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue
index 62b14cde9f..c953a4dc6f 100644
--- a/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue
+++ b/frontend/src/components/DatabaseSchemaReview/SchemaReviewPreview.vue
@@ -2,7 +2,9 @@
<div class="flex gap-x-20">
<aside class="hidden lg:block">
<div class="space-y-6">
- <h1 class="text-left text-2xl font-semibold">Rules</h1>
+ <h1 class="text-left text-2xl font-semibold">
+ {{ $t("schema-review-policy.rules") }}
+ </h1>
<fieldset v-for="(category, index) in categoryList" :key="index">
<div class="block text-sm font-medium text-gray-900">
{{
@@ -18,7 +20,7 @@
:href="`#${rule.type.replace(/\./g, '-')}`"
class="text-gray-600 hover:underline cursor-pointer"
>
- {{ rule.type }}
+ {{ getRuleLocalization(rule.type).title }}
</a>
</div>
</fieldset>
@@ -60,7 +62,7 @@
:id="rule.type.replace(/\./g, '-')"
class="text-left text-xl hover:underline whitespace-nowrap"
>
- {{ rule.type }}
+ {{ getRuleLocalization(rule.type).title }}
</a>
<div class="mt-3 flex items-center space-x-2 sm:mt-0">
<SchemaRuleLevelBadge :level="rule.level" />
@@ -70,7 +72,9 @@
/>
</div>
</div>
- <p class="py-2 text-gray-400">{{ rule.description }}</p>
+ <p class="py-2 text-gray-400">
+ {{ getRuleLocalization(rule.type).description }}
+ </p>
<ul role="list" class="space-y-4 list-disc list-inside">
<li
v-for="(component, i) in rule.componentList"
@@ -110,7 +114,12 @@
<script lang="ts" setup>
import { computed } from "vue";
-import { RuleTemplate, convertToCategoryList, Environment } from "@/types";
+import {
+ RuleTemplate,
+ getRuleLocalization,
+ convertToCategoryList,
+ Environment,
+} from "@/types";
import { environmentName } from "@/utils";
const props = withDefaults(
diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue
index 38879af8c6..65069c4cbf 100644
--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue
+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaReviewTemplates.vue
@@ -9,7 +9,7 @@
>
<div
v-for="(template, index) in templateList"
- :key="template.name"
+ :key="index"
class="relative border border-gray-300 hover:bg-gray-100 rounded-lg p-6 transition-all flex flex-col justify-center items-center w-full sm:max-w-xs"
:class="
index == selectedTemplateIndex
@@ -19,7 +19,7 @@
@click="$emit('select', index)"
>
<img class="h-24" :src="template.imagePath" alt="" />
- <span class="text-lg lg:text-xl mt-4">{{ template.name }}</span>
+ <span class="text-lg lg:text-xl mt-4">{{ template.title }}</span>
<heroicons-solid:check-circle
v-if="index == selectedTemplateIndex"
class="w-7 h-7 text-gray-500 absolute top-3 left-3"
diff --git a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue
index cceb2fd620..ff898c03b7 100644
--- a/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue
+++ b/frontend/src/components/DatabaseSchemaReview/components/SchemaRuleConfig.vue
@@ -13,7 +13,7 @@
<div class="flex-1 flex flex-col ml-3">
<div class="flex mb-2 items-center space-x-2">
<h1 class="text-base font-semibold text-gray-900">
- {{ selectedRule.type }}
+ {{ getRuleLocalization(selectedRule.type).title }}
</h1>
<BBBadge
:text="$t(`engine.${selectedRule.engine.toLowerCase()}`)"
@@ -22,7 +22,7 @@
<SchemaRuleLevelBadge :level="selectedRule.level" />
</div>
<div class="text-sm text-gray-400">
- {{ selectedRule.description }}
+ {{ getRuleLocalization(selectedRule.type).description }}
</div>
</div>
</div>
@@ -60,7 +60,7 @@
class="mb-7"
>
<p class="mb-3">
- {{ config.title }}
+ {{ $t(`schema-review-policy.payload-config.${config.title}`) }}
</p>
<input
v-if="config.payload.type == 'STRING'"
@@ -108,7 +108,8 @@ import { pullAt } from "lodash-es";
import {
LEVEL_LIST,
RuleTemplate,
- RuleTemplatePayload,
+ RuleConfigComponent,
+ getRuleLocalization,
} from "@/types/schemaSystem";
type PayloadValueList = (string | string[])[];
@@ -117,7 +118,7 @@ interface LocalState {
}
const initStatePayload = (
- componentList: RuleTemplatePayload[] | undefined
+ componentList: RuleConfigComponent[] | undefined
): PayloadValueList => {
return (componentList ?? []).reduce((res, component) => {
res.push(component.payload.value ?? component.payload.default);
diff --git a/frontend/src/components/InputWithTemplate/InputWithTemplate.vue b/frontend/src/components/InputWithTemplate/InputWithTemplate.vue
index b3f2f6d940..7ed7b95c97 100644
--- a/frontend/src/components/InputWithTemplate/InputWithTemplate.vue
+++ b/frontend/src/components/InputWithTemplate/InputWithTemplate.vue
@@ -8,8 +8,8 @@
@click="() => onTemplateAdd(template)"
>
{{ template.id }}
- <span class="tooltip whitespace-nowrap">{{
- template.description
+ <span class="tooltip whitespace-nowrap" v-if="template.description">{{
+ $t(template.description)
}}</span>
</div>
</div>
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index 62bc0e5655..9410572927 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -1421,6 +1421,7 @@ schema-review-policy:
remove-review: Successfully removed the review policy.
create-review: Successfully created the review policy.
update-review: Successfully updated the review policy.
+ rules: Rules
filter: Filter
no-permission: Only DBA or Owner has permission to create or update review policy.
disable: Disable schema review policy
@@ -1429,9 +1430,68 @@ schema-review-policy:
category:
engine: Engine
naming: Naming
- query: Query
+ statement: Statement
table: Table
column: Column
+ template:
+ policy-for-prod:
+ title: Schema review for Prod
+ policy-for-dev:
+ title: Schema review for Dev
+ rule:
+ engine-mysql-use-innodb:
+ title: Use Innodb
+ description: Require InnoDB as the storage engine for MySQL.
+ table-require-pk:
+ title: Require primary key
+ description: Require the table to have a primary key.
+ naming-table:
+ title: Table naming check
+ description: Enforce the table name format. Default snake_lower_case.
+ naming-column:
+ title: Column naming check
+ description: Enforce the column name format. Default snake_lower_case.
+ naming-index-pk:
+ title: Primary key naming check
+ description: Enforce the primary key name format. Default pk_{table_name}_{column_name}.
+ naming-index-uk:
+ title: Unique key naming check
+ description: Enforce the unique key name format. Default uk_{table_name}_{column_name}.
+ 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}.
+ naming-index-idx:
+ title: Index naming check
+ description: Enforce the index name format. Default idx_{table_name}_{column_name}.
+ column-required:
+ title: Required columns
+ description: Enforce the required columns in each table.
+ column-no-null:
+ title: Disallow NULL
+ description: Columns cannot have NULL value.
+ statement-select-no-select-all:
+ title: Disallow "SELECT *"
+ description: Disallow 'SELECT *' statement.
+ statement-where-require:
+ title: Require "WHERE"
+ description: Require 'WHERE' clause.
+ statement-where-no-leading-wildcard-like:
+ title: Disallow leading wildcard like
+ description: Disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed.
+ payload-config:
+ table-name-format: Table name format (regex)
+ column-name-format: Column name format (regex)
+ pk-name-format: Primary key name format
+ uk-name-format: Unique key name format
+ idx-name-format: Index name format
+ required-column: Required column names
+ 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
@@ -1442,6 +1502,7 @@ schema-review-policy:
basic-info:
name: Basic info
display-name: Display name
+ display-name-placeholder: The review policy name
display-name-default: Schema review policy
display-name-label: >-
A display name to help identifying among different review policies.
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index cb5e066728..9161a9a458 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -1251,6 +1251,7 @@ schema-review-policy:
remove-review: 审核策略已删除
create-review: 审核策略已创建
update-review: 审核策略已更新
+ rules: 规则
filter: 筛选
no-permission: 仅 DBA 或所有者有权限创建或更新审核策略。
disable: 停用审查策略
@@ -1259,9 +1260,68 @@ schema-review-policy:
category:
engine: 引擎
naming: 命名
- query: 查询
+ statement: 语句
table: 表
column: 列
+ template:
+ policy-for-prod:
+ title: 针对生产环境的审核策略
+ policy-for-dev:
+ title: 针对开发环境的审核策略
+ rule:
+ engine-mysql-use-innodb:
+ title: 使用 InnoDB 作为储存引擎
+ description: 强制要求使用 InnoDB 作为 MySQL 的储存引擎。
+ table-require-pk:
+ title: 强制主键
+ description: 要求每张表必须有一个主键。
+ naming-table:
+ title: 表名命名检查
+ description: 限制表名命名风格,默认为小写字母_下划线。
+ naming-column:
+ title: 列名命名检查
+ description: 限制列名命名风格,默认为小写字母_下划线。
+ naming-index-pk:
+ title: 主键命名检查
+ description: 限制主键命名风格,默认为 pk_表名_主键包含的字段名组合。
+ naming-index-uk:
+ title: 唯一键命名检查
+ description: 限制唯一键命名风格,默认为 uk_表名_主键包含的字段名组合。
+ naming-index-fk:
+ title: 外键命名检查
+ description: 限制外键命名风格,默认为 fk_目标表名_目标字段名_被引用表名_被引用字段名。
+ naming-index-idx:
+ title: 索引命名检查
+ description: 限制索引命名风格,默认为 idx_表名_主键包含的字段名组合。
+ column-required:
+ title: 必须包含的字段
+ description: 强制要求表中必须包含某些字段。
+ column-no-null:
+ title: 禁止字段为 NULL
+ description: 表中的字段不允许存在 NULL 值。
+ statement-select-no-select-all:
+ title: 禁止 "SELECT *"
+ description: 不允许使用 "SELECT *" 语句
+ statement-where-require:
+ title: 强制 "WHERE"
+ description: 必须使用 "WHERE" 语句
+ statement-where-no-leading-wildcard-like:
+ title: 禁止左模糊
+ description: WHERE 语句中禁止使用左模糊匹配,例如禁止 LIKE foo = '%x'。
+ payload-config:
+ table-name-format: 表命名规则(正则)
+ column-name-format: 列命名规则(正则)
+ pk-name-format: 主键命名规则
+ uk-name-format: 唯一键命名规则
+ idx-name-format: 索引命名规则
+ required-column: 必须包含的字段名
+ template:
+ table-name: 表名
+ column-list: 索引包含的字段名,通过 _ 连接
+ referencing-table: 目标表名
+ referencing-column: 目标字段名
+ referenced-table: 被引用的表名
+ referenced-column: 被引用的字段名
error-level:
name: 错误等级
error: 错误
@@ -1272,6 +1332,7 @@ schema-review-policy:
basic-info:
name: 基本信息
display-name: 名称
+ display-name-placeholder: 审核策略名称
display-name-label: 用以区分不同审核策略的名称。
display-name-default: Schema 审核策略
environments: 环境
diff --git a/frontend/src/types/schemaSystem.ts b/frontend/src/types/schemaSystem.ts
index 555d8ed5ea..cda4d3f38f 100644
--- a/frontend/src/types/schemaSystem.ts
+++ b/frontend/src/types/schemaSystem.ts
@@ -1,3 +1,4 @@
+import { useI18n } from "vue-i18n";
import { PolicyId } from "./id";
import { Principal } from "./principal";
import { RowStatus } from "./common";
@@ -7,7 +8,12 @@ import { Environment } from "./environment";
export type SchemaRuleEngineType = "MYSQL" | "COMMON";
// The category type for rule template
-export type CategoryType = "ENGINE" | "NAMING" | "QUERY" | "TABLE" | "COLUMN";
+export type CategoryType =
+ | "ENGINE"
+ | "NAMING"
+ | "STATEMENT"
+ | "TABLE"
+ | "COLUMN";
// The rule level
export enum RuleLevel {
@@ -47,9 +53,9 @@ interface TemplatePayload {
value?: string;
}
-// RuleTemplatePayload is the rule configuration options and default value.
+// RuleConfigComponent is the rule configuration options and default value.
// Used by the frontend.
-export interface RuleTemplatePayload {
+export interface RuleConfigComponent {
title: string;
description: string;
payload: StringPayload | TemplatePayload | StringArrayPayload;
@@ -63,12 +69,13 @@ export type RuleType =
| "naming.column"
| "naming.index.pk"
| "naming.index.uk"
+ | "naming.index.fk"
| "naming.index.idx"
| "column.required"
| "column.no-null"
- | "query.select.no-select-all"
- | "query.where.require"
- | "query.where.no-leading-wildcard-like";
+ | "statement.select.no-select-all"
+ | "statement.where.require"
+ | "statement.where.no-leading-wildcard-like";
// The naming format rule payload.
// Used by the backend.
@@ -91,7 +98,6 @@ export interface SchemaPolicyRule {
}
// The API for schema review policy in backend.
-// TODO: just use the existed Policy entity
export interface DatabaseSchemaReviewPolicy {
id: PolicyId;
@@ -113,28 +119,26 @@ export interface RuleTemplate {
type: RuleType;
category: CategoryType;
engine: SchemaRuleEngineType;
- description: string;
- // TODO: rename componentList to RuleConfigComponent
- componentList: RuleTemplatePayload[];
+ componentList: RuleConfigComponent[];
level: RuleLevel;
}
// SchemaReviewPolicyTemplate is the rule template set
export interface SchemaReviewPolicyTemplate {
- name: string;
+ title: string;
imagePath: 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, RuleTemplatePayload[]> =
+export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleConfigComponent[]> =
new Map([
[
"naming.table",
[
{
- title: "Table name format",
+ title: "table-name-format",
description: "",
payload: {
type: "STRING",
@@ -147,7 +151,7 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
"naming.column",
[
{
- title: "Column name format",
+ title: "column-name-format",
description: "",
payload: {
type: "STRING",
@@ -160,7 +164,7 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
"naming.index.pk",
[
{
- title: "Primary key name format",
+ title: "pk-name-format",
description: "",
payload: {
type: "TEMPLATE",
@@ -168,11 +172,13 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
templateList: [
{
id: "table",
- description: "The table name",
+ description:
+ "schema-review-policy.payload-config.template.table-name",
},
{
id: "column_list",
- description: "Index column names, joined by _",
+ description:
+ "schema-review-policy.payload-config.template.column-list",
},
],
},
@@ -183,7 +189,7 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
"naming.index.uk",
[
{
- title: "Unique key name format",
+ title: "uk-name-format",
description: "",
payload: {
type: "TEMPLATE",
@@ -191,11 +197,49 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
templateList: [
{
id: "table",
- description: "The table name",
+ description:
+ "schema-review-policy.payload-config.template.table-name",
},
{
id: "column_list",
- description: "Index column names, joined by _",
+ 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",
},
],
},
@@ -206,7 +250,7 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
"naming.index.idx",
[
{
- title: "Index name format",
+ title: "idx-name-format",
description: "",
payload: {
type: "TEMPLATE",
@@ -214,11 +258,13 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
templateList: [
{
id: "table",
- description: "The table name",
+ description:
+ "schema-review-policy.payload-config.template.table-name",
},
{
id: "column_list",
- description: "Index column names, joined by _",
+ description:
+ "schema-review-policy.payload-config.template.column-list",
},
],
},
@@ -229,7 +275,7 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
"column.required",
[
{
- title: "Required column names",
+ title: "required-column",
description: "",
payload: {
type: "STRING_ARRAY",
@@ -247,13 +293,11 @@ export const RULE_TEMPLATE_PAYLOAD_MAP: Map<RuleType, RuleTemplatePayload[]> =
]);
// ruleTemplateList stores the default value for each rule template
-// TODO: i18n
export const ruleTemplateList: RuleTemplate[] = [
{
type: "engine.mysql.use-innodb",
category: "ENGINE",
engine: "MYSQL",
- description: "Require InnoDB as the storage engine.",
level: RuleLevel.ERROR,
componentList: [],
},
@@ -261,7 +305,6 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "table.require-pk",
category: "TABLE",
engine: "COMMON",
- description: "Require the table to have a primary key.",
level: RuleLevel.ERROR,
componentList: [],
},
@@ -269,7 +312,6 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "naming.table",
category: "NAMING",
engine: "COMMON",
- description: "Enforce the table name format. Default snake_lower_case.",
componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.table") ?? [],
level: RuleLevel.ERROR,
},
@@ -277,7 +319,6 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "naming.column",
category: "NAMING",
engine: "COMMON",
- description: "Enforce the column name format. Default snake_lower_case.",
componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.column") ?? [],
level: RuleLevel.ERROR,
},
@@ -285,7 +326,6 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "naming.index.pk",
category: "NAMING",
engine: "COMMON",
- description: "Enforce the primary key name format.",
componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.index.pk") ?? [],
level: RuleLevel.ERROR,
},
@@ -293,15 +333,20 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "naming.index.uk",
category: "NAMING",
engine: "COMMON",
- description: "Enforce the unique key name format.",
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",
- description: "Enforce the index name format.",
componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("naming.index.idx") ?? [],
level: RuleLevel.ERROR,
},
@@ -309,7 +354,6 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "column.required",
category: "COLUMN",
engine: "COMMON",
- description: "Enforce the required columns in each table.",
componentList: RULE_TEMPLATE_PAYLOAD_MAP.get("column.required") ?? [],
level: RuleLevel.ERROR,
},
@@ -317,32 +361,27 @@ export const ruleTemplateList: RuleTemplate[] = [
type: "column.no-null",
category: "COLUMN",
engine: "COMMON",
- description: "Columns cannot have NULL value.",
level: RuleLevel.ERROR,
componentList: [],
},
{
- type: "query.select.no-select-all",
- category: "QUERY",
+ type: "statement.select.no-select-all",
+ category: "STATEMENT",
engine: "COMMON",
- description: "Disallow 'SELECT *'.",
level: RuleLevel.ERROR,
componentList: [],
},
{
- type: "query.where.require",
- category: "QUERY",
+ type: "statement.where.require",
+ category: "STATEMENT",
engine: "COMMON",
- description: "Require 'WHERE' clause.",
level: RuleLevel.ERROR,
componentList: [],
},
{
- type: "query.where.no-leading-wildcard-like",
- category: "QUERY",
+ type: "statement.where.no-leading-wildcard-like",
+ category: "STATEMENT",
engine: "COMMON",
- description:
- "Disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed.",
level: RuleLevel.ERROR,
componentList: [],
},
@@ -360,7 +399,7 @@ export const convertToCategoryList = (
const categoryOrder: Map<CategoryType, number> = new Map([
["ENGINE", 5],
["NAMING", 4],
- ["QUERY", 3],
+ ["STATEMENT", 3],
["TABLE", 2],
["COLUMN", 1],
]);
@@ -422,6 +461,7 @@ export const convertPolicyRuleToRuleTemplate = (
case "naming.index.idx":
case "naming.index.pk":
case "naming.index.uk":
+ case "naming.index.fk":
const templateComponent = ruleTemplate.componentList[0];
const indexRulePayload = {
...templateComponent.payload,
@@ -482,6 +522,7 @@ export const convertRuleTemplateToPolicyRule = (
case "naming.index.idx":
case "naming.index.pk":
case "naming.index.uk":
+ case "naming.index.fk":
const templatePayload = rule.componentList[0].payload as TemplatePayload;
return {
...base,
@@ -502,3 +543,18 @@ export const convertRuleTemplateToPolicyRule = (
throw new Error(`Invalid rule ${rule.type}`);
};
+
+export const getRuleLocalization = (
+ type: RuleType
+): { title: string; description: string } => {
+ const { t } = useI18n();
+ const key = type.split(".").join("-");
+
+ const title = t(`schema-review-policy.rule.${key}.title`);
+ const description = t(`schema-review-policy.rule.${key}.description`);
+
+ return {
+ title,
+ description,
+ };
+};