diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vue index a3c914920a..6c9c1d4bb3 100644 --- a/apps/desktop/src/components/structure/TableStructureEditor.vue +++ b/apps/desktop/src/components/structure/TableStructureEditor.vue @@ -43,7 +43,7 @@ import { combineDataTypeForDatabase, createColumnDrafts, createIndexDrafts, - DATA_TYPE_OPTIONS, + getDataTypeOptions, getDefaultLengthForType, splitDataType, toColumnNames, @@ -137,7 +137,7 @@ const connection = computed(() => (props.connectionId ? store.getConfig(props.co const databaseType = computed(() => connection.value?.db_type); const structureCapabilities = computed(() => getTableStructureCapabilities(databaseType.value)); const isTableCommentDisabled = computed(() => !structureCapabilities.value.comment); -const dataTypeOptions = computed(() => DATA_TYPE_OPTIONS[databaseType.value ?? ""] ?? []); +const dataTypeOptions = computed(() => getDataTypeOptions(databaseType.value)); const indexTypesByDb: Record = { postgres: ["BTREE", "HASH", "GIST", "SPGIST", "GIN", "BRIN"], diff --git a/apps/desktop/src/lib/tableStructureEditorState.ts b/apps/desktop/src/lib/tableStructureEditorState.ts index 236dd7ec2c..85c68e2b08 100644 --- a/apps/desktop/src/lib/tableStructureEditorState.ts +++ b/apps/desktop/src/lib/tableStructureEditorState.ts @@ -230,6 +230,27 @@ export const DATA_TYPE_OPTIONS: Record = { ], }; +const DATA_TYPE_OPTION_ALIASES: Partial> = { + doris: "mysql", + starrocks: "mysql", + goldendb: "mysql", + sundb: "mysql", + gaussdb: "postgres", + opengauss: "postgres", + redshift: "postgres", + highgo: "postgres", + vastbase: "postgres", + kingbase: "postgres", + dameng: "oracle", + "oceanbase-oracle": "oracle", + iris: "oracle", +}; + +export function getDataTypeOptions(dbType: DatabaseType | undefined): string[] { + const key = dbType ? (DATA_TYPE_OPTION_ALIASES[dbType] ?? dbType) : ""; + return DATA_TYPE_OPTIONS[key] ?? []; +} + export const DEFAULT_TYPE_LENGTHS: Record = { tinyint: "4", smallint: "6", diff --git a/packages/app-tests/tableStructureEditorState.test.ts b/packages/app-tests/tableStructureEditorState.test.ts index 8a45b1009b..324e0f2c28 100644 --- a/packages/app-tests/tableStructureEditorState.test.ts +++ b/packages/app-tests/tableStructureEditorState.test.ts @@ -5,6 +5,7 @@ import { combineDataTypeForDatabase, createColumnDrafts, createIndexDrafts, + getDataTypeOptions, normalizeDataTypeParams, parseExtraToColumnExtra, toColumnNames, @@ -159,3 +160,11 @@ test("normalizes temporal precision when combining data types", () => { assert.equal(normalizeDataTypeParams("oracle", "timestamp", "9"), "9"); assert.equal(normalizeDataTypeParams("oracle", "timestamp", "10"), ""); }); + +test("returns data type options for compatible table structure editors", () => { + assert.deepEqual(getDataTypeOptions("dameng"), getDataTypeOptions("oracle")); + assert.deepEqual(getDataTypeOptions("gaussdb"), getDataTypeOptions("postgres")); + assert.deepEqual(getDataTypeOptions("doris"), getDataTypeOptions("mysql")); + assert.equal(getDataTypeOptions("dameng").includes("varchar2"), true); + assert.equal(getDataTypeOptions("sqlserver").includes("nvarchar"), true); +});