25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(mysql): 修复 enum/set 字段长度显示异常
zipg38d300bd35d5
diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vueindex 3ef20272f4..a85906ecb7 100644--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue@@ -67,7 +67,7 @@ import { normalizeSidebarHiddenTablePrefixes } from "@/lib/sidebarTableNameDisplimport { normalizeSqlFormatterSettings, type SqlFormatterSettings } from "@/lib/sqlFormatterConfig";import { EMPTY_TABLE_COLUMN_TEMPLATE_DATA_TYPE, parseTableColumnTemplateFields, TABLE_COLUMN_TEMPLATE_DATABASE_TYPES } from "@/lib/tableColumnTemplates";import { buildMcpCodexConfig, buildMcpJsonConfig, buildMcpOpenCodeConfig, buildMcpVsCodeConfig, type McpEnvEntry } from "@/lib/mcpConfigTemplates";-import { combineDataTypeForDatabase, getDataTypeOptions, getDefaultLengthForType, isDataTypeLengthDisabled, splitDataType } from "@/lib/tableStructureEditorState";+import { combineDataTypeForDatabase, dataTypeLengthInputValue, getDataTypeOptions, getDefaultLengthForType, isDataTypeLengthDisabled, splitDataType } from "@/lib/tableStructureEditorState";import type { DatabaseType, SqlSnippet } from "@/types/database";import { uuid } from "@/lib/utils";import { DEFAULT_SQL_SNIPPETS } from "@/lib/sqlCompletion";@@ -815,7 +815,7 @@ function tableColumnTemplateBaseTypeForSelectedDatabase(row: TableColumnTemplate}function tableColumnTemplateLengthForSelectedDatabase(row: TableColumnTemplateGridRow): string {- return splitDataType(tableColumnTemplateDataTypeForSelectedDatabase(row)).params;+ return dataTypeLengthInputValue(editTableColumnTemplateDatabaseType.value, tableColumnTemplateDataTypeForSelectedDatabase(row));}function setTableColumnTemplateDataTypeForSelectedDatabase(row: TableColumnTemplateGridRow, value: string) {diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vueindex 089bac6665..e025b6120f 100644--- a/apps/desktop/src/components/structure/TableStructureEditor.vue+++ b/apps/desktop/src/components/structure/TableStructureEditor.vue@@ -34,6 +34,7 @@ import {createForeignKeyDrafts,createIndexDrafts,createTriggerDrafts,+ dataTypeLengthInputValue,generateIndexName,generateUniqueIndexName,getColumnEditorControls,@@ -1506,7 +1507,12 @@ watch(activeTab, (tab) => {<Input v-else :model-value="splitDataType(column.dataType).baseType" :class="[structureMonoControlClass, 'w-full']" disabled /></td><td v-if="columnEditorControls.length" :class="structureCellClass">- <Input :model-value="splitDataType(column.dataType).params" :class="structureMonoControlClass" :disabled="isColumnLengthDisabled(column)" @update:model-value="column.dataType = combineDataTypeForDatabase(databaseType, splitDataType(column.dataType).baseType, String($event))" />+ <Input+ :model-value="dataTypeLengthInputValue(databaseType, column.dataType)"+ :class="structureMonoControlClass"+ :disabled="isColumnLengthDisabled(column)"+ @update:model-value="column.dataType = combineDataTypeForDatabase(databaseType, splitDataType(column.dataType).baseType, String($event))"+ /></td><td v-if="columnEditorControls.nullable" :class="structureCellClass"><label class="flex items-center gap-1.5">diff --git a/apps/desktop/src/lib/__tests__/tableStructureEditorState.spec.ts b/apps/desktop/src/lib/__tests__/tableStructureEditorState.spec.tsindex b4fb11c0f4..41bc8584ee 100644--- a/apps/desktop/src/lib/__tests__/tableStructureEditorState.spec.ts+++ b/apps/desktop/src/lib/__tests__/tableStructureEditorState.spec.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { combineDataTypeForDatabase, splitDataType } from "../tableStructureEditorState";+import { combineDataTypeForDatabase, dataTypeLengthInputValue, isDataTypeLengthDisabled, splitDataType } from "../tableStructureEditorState";describe("tableStructureEditorState", () => {it("keeps mysql unsigned attributes in the editable base type", () => {@@ -14,4 +14,17 @@ describe("tableStructureEditorState", () => {expect(combineDataTypeForDatabase("mysql", "int unsigned", "11")).toBe("int(11) unsigned");expect(combineDataTypeForDatabase("mysql", "bigint unsigned zerofill", "20")).toBe("bigint(20) unsigned zerofill");});++ it("does not expose mysql enum or set values as editable length", () => {+ const dataType = "enum('purchase_in','sale_out','return_in','adjustment_out','transfer_in','transfer_out')";++ expect(splitDataType(dataType)).toEqual({+ baseType: "enum",+ params: "'purchase_in','sale_out','return_in','adjustment_out','transfer_in','transfer_out'",+ });+ expect(isDataTypeLengthDisabled("mysql", "enum")).toBe(true);+ expect(isDataTypeLengthDisabled("mysql", "set")).toBe(true);+ expect(dataTypeLengthInputValue("mysql", dataType)).toBe("");+ expect(dataTypeLengthInputValue("mysql", "set('manual','auto')")).toBe("");+ });});diff --git a/apps/desktop/src/lib/tableStructureEditorState.ts b/apps/desktop/src/lib/tableStructureEditorState.tsindex 5d3a6419b7..9af8600edb 100644--- a/apps/desktop/src/lib/tableStructureEditorState.ts+++ b/apps/desktop/src/lib/tableStructureEditorState.ts@@ -693,6 +693,11 @@ export function combineDataTypeForDatabase(dbType: DatabaseType | undefined, basreturn combineDataType(baseType, normalizedParams);}+export function dataTypeLengthInputValue(dbType: DatabaseType | undefined, rawDataType: string): string {+ const parsed = splitDataType(rawDataType);+ return isDataTypeLengthDisabled(dbType, parsed.baseType) ? "" : parsed.params;+}+export function normalizeDataTypeParams(dbType: DatabaseType | undefined, baseType: string, params: string): string {const p = params.trim();if (!p) return "";@@ -770,6 +775,8 @@ export function isDataTypeLengthDisabled(_dbType: DatabaseType | undefined, basereturn key !== "bit" && key !== "float_vector";} else if (_dbType === "postgres" || _dbType === "gaussdb" || _dbType === "kwdb" || _dbType === "opengauss" || _dbType === "highgo" || _dbType === "vastbase" || _dbType === "kingbase") {return POSTGRES_TYPE_LENGTH_DISABLES.includes(key);+ } else if (isMysqlLikeStructureType(_dbType)) {+ return key === "enum" || key === "set";} else {return DEFAULT_TYPE_LENGTH_DISABLES.includes(key);}