Skip to content

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

chore: update getRuleLocalization to support engine-specific localization (#14196)

boojack448fcc04283c
diff --git a/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
index b2992ad7de..6c19104c66 100644
--- a/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue
@@ -367,7 +367,7 @@ const builtinRuleLevel = (type: string): SQLReviewRuleLevel => {
case "builtin.prior-backup-check":
return SQLReviewRuleLevel.ERROR;
case "builtin.object-owner-check":
- return SQLReviewRuleLevel.WARNING
+ return SQLReviewRuleLevel.WARNING;
default:
return SQLReviewRuleLevel.ERROR;
}
@@ -387,7 +387,7 @@ const categoryAndTitle = (
}
const rule = getRuleTemplateByType(checkResult.title);
if (rule) {
- const ruleLocalization = getRuleLocalization(rule.type);
+ const ruleLocalization = getRuleLocalization(rule.type, rule.engine);
const key = `sql-review.category.${rule.category.toLowerCase()}`;
const category = t(key);
const title = messageWithCode(ruleLocalization.title, code);
diff --git a/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue b/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue
index 07083555ce..8c1d22b9c3 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue
@@ -1,6 +1,6 @@
<template>
<BBModal
- :title="getRuleLocalization(rule.type).title"
+ :title="getRuleLocalization(rule.type, rule.engine).title"
@close="$emit('cancel')"
>
<div class="space-y-4 w-[calc(100vw-5rem)] sm:w-[40rem] pb-1">
@@ -19,7 +19,7 @@
</div>
</div>
<div class="textinfolabel flex items-center gap-x-2">
- {{ getRuleLocalization(rule.type).title }}
+ {{ getRuleLocalization(rule.type, rule.engine).title }}
<a
:href="`https://www.bytebase.com/docs/sql-review/review-rules#${rule.type}`"
target="__blank"
@@ -62,7 +62,7 @@
v-model:value="state.comment"
:disabled="disabled"
:placeholder="
- getRuleLocalization(rule.type).description ||
+ getRuleLocalization(rule.type, rule.engine).description ||
$t('common.description')
"
type="textarea"
@@ -121,7 +121,8 @@ const ruleConfig = ref<InstanceType<typeof RuleConfig>>();
const state = reactive<LocalState>({
level: props.rule.level,
comment:
- props.rule.comment || getRuleLocalization(props.rule.type).description,
+ props.rule.comment ||
+ getRuleLocalization(props.rule.type, props.rule.engine).description,
});
const toggleActivity = (on: boolean) => {
diff --git a/frontend/src/components/SQLReview/components/SQLRuleFilter.vue b/frontend/src/components/SQLReview/components/SQLRuleFilter.vue
index b6ba88d99e..14c0c90117 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleFilter.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleFilter.vue
@@ -87,7 +87,7 @@ const filterRuleByKeyword = (rule: RuleTemplateV2, searchText: string) => {
const keyword = searchText.trim().toLowerCase();
if (!keyword) return true;
if (rule.type.toLowerCase().includes(keyword)) return true;
- const localization = getRuleLocalization(rule.type);
+ const localization = getRuleLocalization(rule.type, rule.engine);
if (localization.title.toLowerCase().includes(keyword)) return true;
if (localization.description.toLowerCase().includes(keyword)) return true;
return false;
diff --git a/frontend/src/components/SQLReview/components/SQLRuleTable.vue b/frontend/src/components/SQLReview/components/SQLRuleTable.vue
index 59b807c70b..4b127b958b 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleTable.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleTable.vue
@@ -63,7 +63,7 @@
</span>
</NTooltip>
<span>
- {{ getRuleLocalization(rule.type).title }}
+ {{ getRuleLocalization(rule.type, rule.engine).title }}
<a
:href="`https://www.bytebase.com/docs/sql-review/review-rules#${rule.type}`"
target="_blank"
@@ -100,7 +100,7 @@
@level-change="updateLevel(rule, $event)"
/>
<p class="textinfolabel">
- {{ getRuleLocalization(rule.type).description }}
+ {{ getRuleLocalization(rule.type, rule.engine).description }}
</p>
</div>
</div>
@@ -199,13 +199,14 @@ const columns = computed(() => {
expandable: (rule: RuleTemplateV2) => {
return !!(
rule.comment ||
- getRuleLocalization(rule.type).description ||
+ getRuleLocalization(rule.type, rule.engine).description ||
rule.componentList.length > 0
);
},
renderExpand: (rule: RuleTemplateV2) => {
const comment =
- rule.comment || getRuleLocalization(rule.type).description;
+ rule.comment ||
+ getRuleLocalization(rule.type, rule.engine).description;
return (
<div class="px-10">
<p class="w-full text-left text-gray-500">{comment}</p>
@@ -254,7 +255,7 @@ const columns = computed(() => {
render: (rule: RuleTemplateV2) => {
return (
<div class="flex items-center space-x-2">
- <span>{getRuleLocalization(rule.type).title}</span>
+ <span>{getRuleLocalization(rule.type, rule.engine).title}</span>
<a
href={`https://www.bytebase.com/docs/sql-review/review-rules#${rule.type}`}
target="_blank"
diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.json
index 73bd5d095b..8203300397 100644
--- a/frontend/src/locales/sql-review/en-US.json
+++ b/frontend/src/locales/sql-review/en-US.json
@@ -568,8 +568,16 @@
"description": "Some changes may affect running applications, such as modifying the name of database object, adding new constraints, etc. This rule can avoid careless changes that lead to the failure of existing application. Suggestion error level: Warning"
},
"statement-max-execution-time": {
- "title": "Max execution time",
- "description": "Set the maximum execution time for SQL statements. If the execution time exceeds the limit, the statement will be terminated. Suggestion error level: Error"
+ "title": "Enforce set the max execution time parameter",
+ "description": "Set the maximum execution time for SQL statements. If the execution time exceeds the limit, the statement will be terminated. Suggestion error level: Warning",
+ "mysql": {
+ "title": "Enforce set the MAX_EXECUTION_TIME parameter explicitly",
+ "description": "Set the MAX_EXECUTION_TIME parameter in the change script to explicitly control the maximum execution time of the statement. Suggestion error level: Warning"
+ },
+ "mariadb": {
+ "title": "Enforce set the MAX_STATEMENT_TIME parameter explicitly",
+ "description": "Set the MAX_STATEMENT_TIME parameter in the change script to explicitly control the maximum execution time of the statement. Suggestion error level: Warning"
+ }
},
"statement-require-algorithm-option": {
"title": "Require specifying the ALGORITHM option in ALTER TABLE statements",
diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.json
index 138bb08107..b1a4302ca1 100644
--- a/frontend/src/locales/sql-review/es-ES.json
+++ b/frontend/src/locales/sql-review/es-ES.json
@@ -568,8 +568,16 @@
"description": "Algunos cambios pueden afectar las aplicaciones en ejecución, como modificar el nombre del objeto de la base de datos, agregar nuevas restricciones, etc. Esta regla puede evitar cambios descuidados que lleven al fallo de la aplicación existente. Nivel de error sugerido: Advertencia"
},
"statement-max-execution-time": {
- "title": "Tiempo máximo de ejecución",
- "description": "Establezca el tiempo máximo de ejecución de las sentencias SQL. Si el tiempo de ejecución supera el límite, la sentencia finalizará. Nivel de error sugerido: Error"
+ "title": "Aplicar el parámetro de tiempo máximo de ejecución",
+ "description": "Establezca el tiempo máximo de ejecución de las sentencias SQL. Si el tiempo de ejecución supera el límite, la sentencia finalizará. Nivel de error sugerido: Advertencia",
+ "mysql": {
+ "title": "Exigir que se establezca el parámetro MAX_EXECUTION_TIME explícitamente",
+ "description": "Establezca el parámetro MAX_EXECUTION_TIME en el script de cambio para controlar explícitamente el tiempo máximo de ejecución de la instrucción. Nivel de error sugerido: Advertencia"
+ },
+ "mariadb": {
+ "title": "Exigir que se establezca el parámetro MAX_STATEMENT_TIME explícitamente",
+ "description": "Establezca el parámetro MAX_STATEMENT_TIME en el script de cambio para controlar explícitamente el tiempo máximo de ejecución de la declaración. Nivel de error sugerido: Advertencia"
+ }
},
"statement-require-algorithm-option": {
"title": "Requiere especificar la opción ALGORITMO en las instrucciones ALTER TABLE",
diff --git a/frontend/src/locales/sql-review/ja-JP.json b/frontend/src/locales/sql-review/ja-JP.json
index efa6be1fed..830698bd6a 100644
--- a/frontend/src/locales/sql-review/ja-JP.json
+++ b/frontend/src/locales/sql-review/ja-JP.json
@@ -568,8 +568,16 @@
"description": "一部の変更は実行中のアプリケーションに影響を与える可能性があります。データベースオブジェクトの名前の変更や新しい制約の追加などが該当します。このルールにより、既存のアプリケーションの障害を防ぐことができます。提案されるエラーレベル:警告"
},
"statement-max-execution-time": {
- "title": "最大実行時間",
- "description": "SQL 文の最大実行時間を設定します。実行時間が制限を超えると、文は終了します。提案エラー レベル: エラー"
+ "title": "最大実行時間パラメータの設定を強制する",
+ "description": "SQL 文の最大実行時間を設定します。実行時間が制限を超えると、文は終了します。提案エラー レベル: 警告",
+ "mysql": {
+ "title": "MAX_EXECUTION_TIMEパラメータを明示的に設定する",
+ "description": "変更スクリプトで MAX_EXECUTION_TIME パラメータを設定して、ステートメントの最大実行時間を明示的に制御します。提案エラー レベル: 警告"
+ },
+ "mariadb": {
+ "title": "MAX_STATEMENT_TIMEパラメータを明示的に設定する",
+ "description": "変更スクリプトで MAX_STATEMENT_TIME パラメータを設定して、ステートメントの最大実行時間を明示的に制御します。提案エラー レベル: 警告"
+ }
},
"statement-require-algorithm-option": {
"title": "ALTER TABLE文でALGORITHMオプションを指定する必要がある",
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index ca1c7808dc..c6c91dc6c8 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -568,8 +568,16 @@
"description": "某些变更可能影响现有应用功能,例如修改数据库对象名,增加新的约束等,此规范可避免不谨慎变更导致现有应用运行失败。建议错误等级:警告"
},
"statement-max-execution-time": {
- "title": "最大执行时间",
- "description": "设置SQL语句的最大执行时间,如果执行时间超过限制,语句将被终止。建议错误级别:错误"
+ "title": "强制设置最大执行时间参数",
+ "description": "设置SQL语句的最大执行时间,如果执行时间超过限制,语句将被终止。建议错误级别:警告",
+ "mysql": {
+ "title": "强制明确设置 MAX_EXECUTION_TIME 参数",
+ "description": "在变更脚本中设置 MAX_EXECUTION_TIME 参数以显式控制语句最长执行时间。建议错误级别:警告"
+ },
+ "mariadb": {
+ "title": "强制明确设置 MAX_STATEMENT_TIME 参数",
+ "description": "在变更脚本中设置 MAX_STATEMENT_TIME 参数以显式控制语句最长执行时间。建议错误级别:警告"
+ }
},
"statement-require-algorithm-option": {
"title": "需要在 ALTER TABLE 语句中指定 ALGORITHM 选项",
@@ -723,4 +731,4 @@
"warning": "警告",
"disabled": "禁用"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/types/sqlReview.ts b/frontend/src/types/sqlReview.ts
index a1f117a4b3..29ec28085b 100644
--- a/frontend/src/types/sqlReview.ts
+++ b/frontend/src/types/sqlReview.ts
@@ -1,4 +1,4 @@
-import { t } from "@/plugins/i18n";
+import { t, te } from "@/plugins/i18n";
import type { Engine } from "@/types/proto/v1/common";
import { engineFromJSON } from "@/types/proto/v1/common";
import {
@@ -743,12 +743,22 @@ export const getRuleLocalizationKey = (type: string): string => {
};
export const getRuleLocalization = (
- type: string
+ type: string,
+ engine?: Engine
): { title: string; description: string } => {
const key = getRuleLocalizationKey(type);
+ let title = t(`sql-review.rule.${key}.title`);
+ let description = t(`sql-review.rule.${key}.description`);
- const title = t(`sql-review.rule.${key}.title`);
- const description = t(`sql-review.rule.${key}.description`);
+ if (engine) {
+ const engineSpecificKey = `${key}.${engine.toLowerCase()}`;
+ if (te(`sql-review.rule.${engineSpecificKey}.title`)) {
+ title = t(`sql-review.rule.${engineSpecificKey}.title`);
+ }
+ if (te(`sql-review.rule.${engineSpecificKey}.description`)) {
+ description = t(`sql-review.rule.${engineSpecificKey}.description`);
+ }
+ }
return {
title,