Skip to content

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

chore: update table/column name regexp (#3695)

boojacke71fb6e6891c
diff --git a/frontend/src/components/UIEditor/Panels/TableEditor.vue b/frontend/src/components/UIEditor/Panels/TableEditor.vue
index fb25beacee..7ce39865cc 100644
--- a/frontend/src/components/UIEditor/Panels/TableEditor.vue
+++ b/frontend/src/components/UIEditor/Panels/TableEditor.vue
@@ -193,8 +193,8 @@ import { getDataTypeSuggestionList } from "@/utils";
import { diffTableList } from "@/utils/UIEditor/diffTable";
import HighlightCodeBlock from "@/components/HighlightCodeBlock";
-const columnNameFieldRegexp = /\S+/;
-const columnTypeFieldRegexp = /\S+/;
+const tableOrColumnNameFieldRegexp = /^\S+$/;
+const columnTypeFieldRegexp = /^\S+$/;
interface LocalState {
isFetchingDDL: boolean;
@@ -254,11 +254,11 @@ const dataTypeOptions = computed(() => {
});
const handleSaveChanges = async () => {
- if (tableCache.name === "") {
+ if (!tableOrColumnNameFieldRegexp.test(tableCache.name)) {
notificationStore.pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: "Table name cannot be empty",
+ title: t("ui-editor.message.invalid-table-name"),
});
return;
}
@@ -272,17 +272,28 @@ const handleSaveChanges = async () => {
notificationStore.pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: "Invalid table name: duplicate with others",
+ title: t("ui-editor.message.duplicated-table-name"),
});
return;
}
for (const column of tableCache.columnList) {
- if (!columnNameFieldRegexp.test(column.name)) {
+ if (!tableOrColumnNameFieldRegexp.test(column.name)) {
notificationStore.pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: "Invalid column name",
+ title: t("ui-editor.message.invalid-column-name"),
+ });
+ return;
+ }
+ const foundColumnListByName = tableCache.columnList.filter(
+ (item) => item.name === column.name
+ );
+ if (foundColumnListByName.length > 1) {
+ notificationStore.pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("ui-editor.message.duplicated-column-name"),
});
return;
}
@@ -290,7 +301,7 @@ const handleSaveChanges = async () => {
notificationStore.pushNotification({
module: "bytebase",
style: "CRITICAL",
- title: "Invalid column type",
+ title: t("ui-editor.message.invalid-column-type"),
});
return;
}
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 940ed83d40..ff363a1edf 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1430,7 +1430,14 @@
"comment": "Comment",
"is-nullable": "Is Nullable"
},
- "nothing-changed": "Nothing changed"
+ "nothing-changed": "Nothing changed",
+ "message": {
+ "invalid-table-name": "Invalid table name",
+ "duplicated-table-name": "Duplicated table name",
+ "invalid-column-name": "Invalid column name",
+ "duplicated-column-name": "Duplicated column name",
+ "invalid-column-type": "Invalid column type"
+ }
},
"label": {
"empty-label-value": "<Empty Value>",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 41251ad480..108f9e4dcf 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1430,7 +1430,14 @@
"comment": "注释",
"nullable": "是否可为空"
},
- "nothing-changed": "无任何改动"
+ "nothing-changed": "无任何改动",
+ "message": {
+ "invalid-table-name": "无效的表名",
+ "duplicated-table-name": "重复的表名",
+ "invalid-column-name": "无效的列名",
+ "duplicated-column-name": "重复的列名",
+ "invalid-column-type": "无效的列类型"
+ }
},
"label": {
"empty-label-value": "<空值>",