From c99c0d932c9d88ca21bf5c9cd7de008f94a19f7a Mon Sep 17 00:00:00 2001 From: zipg Date: Thu, 3 Sep 2026 12:34:10 +0800 Subject: [PATCH] fix(table): hide unsupported identity column for opengauss --- .../structure/TableStructureEditor.vue | 16 ++++++---------- .../src/lib/table/tableStructureEditorState.ts | 18 +++++++++++++++++- .../tableStructureEditorState.test.ts | 11 ++++++++--- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vue index a615b69b1c..3178f5baeb 100644 --- a/apps/desktop/src/components/structure/TableStructureEditor.vue +++ b/apps/desktop/src/components/structure/TableStructureEditor.vue @@ -89,6 +89,7 @@ import { resolveInsertColumnIndex, restoreCharacterLengthUnitsAfterSave, sameStructureIndexType, + supportsTableStructureExtendedProperties, structureColumnSelectionRange, isSyntheticContextMenuClick, resolveColumnSelectionActiveId, @@ -420,7 +421,7 @@ function columnChanged(column: EditableStructureColumn, index: number): boolean column.isPrimaryKey !== original.is_primary_key || !sameText(column.characterSet, original.character_set) || !sameText(column.collation, original.collation) || - JSON.stringify(column.extra) !== JSON.stringify(parseExtraToColumnExtra(original.extra, databaseType.value)) + (showExtendedProperties.value && JSON.stringify(column.extra) !== JSON.stringify(parseExtraToColumnExtra(original.extra, databaseType.value))) ); } @@ -922,14 +923,7 @@ const defaultValuePresets = computed((): DefaultValuePreset[] => { return [...universal, ...(dialectPresets[structureDialect.value] ?? [])]; }); -function isPostgresIdentityType(dbType: string | undefined): boolean { - return dbType === "postgres" || dbType === "gaussdb" || dbType === "kwdb" || dbType === "opengauss" || dbType === "highgo" || dbType === "uxdb" || dbType === "vastbase" || dbType === "kingbase"; -} - -const showExtendedProperties = computed(() => { - const dt = databaseType.value; - return dt === "mysql" || dt === "dameng" || dt === "manticoresearch" || isPostgresIdentityType(dt) || dt === "sqlserver"; -}); +const showExtendedProperties = computed(() => supportsTableStructureExtendedProperties(databaseType.value)); const showCharacterSet = computed(() => structureDialect.value === "mysql"); const serverCharsetMetadata = ref(); @@ -1611,7 +1605,9 @@ function structureChangeOptions(): BuildTableStructureChangeSqlOptions { databaseType: databaseType.value, schema: props.schema, tableName: isCreateMode.value ? newTableName.value.trim() : props.tableName || "", - columns: columns.value, + // Do not let a draft created by an older build submit properties that the + // current database cannot represent (notably PostgreSQL-style identity on openGauss). + columns: showExtendedProperties.value ? columns.value : columns.value.map((column) => ({ ...column, extra: {} })), indexes: sanitizeStructureIndexesForCapabilities(indexes.value, structureCapabilities.value), foreignKeys: foreignKeys.value, triggers: triggers.value, diff --git a/apps/desktop/src/lib/table/tableStructureEditorState.ts b/apps/desktop/src/lib/table/tableStructureEditorState.ts index 7b086478b5..4d5d328f2b 100644 --- a/apps/desktop/src/lib/table/tableStructureEditorState.ts +++ b/apps/desktop/src/lib/table/tableStructureEditorState.ts @@ -632,6 +632,22 @@ const XUGU_TYPE_LENGTH_DISABLES = new Set([...ORACLE_LIKE_TYPE_LENGTH_DISABLES, export const SQLSERVER_TYPE_LENGTH_DISABLES: string[] = ["bigint", "bit", "date", "datetime", "image", "int", "integer", "money", "ntext", "real", "smalldatetime", "smallint", "smallmoney", "sql_variant", "text", "timestamp", "tinyint", "uniqueidentifier", "xml"]; +export function supportsTableStructureExtendedProperties(databaseType?: DatabaseType): boolean { + return ( + databaseType === "mysql" || + databaseType === "dameng" || + databaseType === "manticoresearch" || + databaseType === "sqlserver" || + databaseType === "postgres" || + databaseType === "gaussdb" || + databaseType === "kwdb" || + databaseType === "highgo" || + databaseType === "uxdb" || + databaseType === "vastbase" || + databaseType === "kingbase" + ); +} + export function parseExtraToColumnExtra(extra: string | null | undefined, databaseType?: DatabaseType): ColumnExtra { const result: ColumnExtra = {}; if (!extra) return result; @@ -645,7 +661,7 @@ export function parseExtraToColumnExtra(extra: string | null | undefined, databa if (lower.includes("on update current_timestamp")) { result.onUpdateCurrentTimestamp = true; } - } else if (databaseType === "postgres" || databaseType === "gaussdb" || databaseType === "kwdb" || databaseType === "opengauss" || databaseType === "questdb" || databaseType === "highgo" || databaseType === "uxdb" || databaseType === "vastbase" || databaseType === "kingbase") { + } else if (databaseType === "postgres" || databaseType === "gaussdb" || databaseType === "kwdb" || databaseType === "questdb" || databaseType === "highgo" || databaseType === "uxdb" || databaseType === "vastbase" || databaseType === "kingbase") { const identityMatch = lower.match(/generated\s+(by\s+default|always)\s+as\s+identity/i); if (identityMatch) { const sequenceMatch = lower.match(/start\s+with\s*(-?\d+)\s+increment\s+by\s*(-?\d+)/i); diff --git a/packages/app-tests/tableStructureEditorState.test.ts b/packages/app-tests/tableStructureEditorState.test.ts index 5418f9028e..2ffe4de2df 100644 --- a/packages/app-tests/tableStructureEditorState.test.ts +++ b/packages/app-tests/tableStructureEditorState.test.ts @@ -27,6 +27,7 @@ import { rehydrateColumnDraftsFromMetadata, resolveInsertColumnIndex, sameStructureIndexType, + supportsTableStructureExtendedProperties, toColumnNames, } from "../../apps/desktop/src/lib/table/tableStructureEditorState.ts"; import { firstStructureMetadataTab, isStructureMetadataTabSupported } from "../../apps/desktop/src/lib/table/tableMetadataCapabilities.ts"; @@ -290,9 +291,7 @@ test("parses PostgreSQL extra string to ColumnExtra", () => { assert.deepEqual(parseExtraToColumnExtra("generated by default as identity", "postgres"), { identity: { generation: "BY DEFAULT" }, }); - assert.deepEqual(parseExtraToColumnExtra("generated by default as identity", "opengauss"), { - identity: { generation: "BY DEFAULT" }, - }); + assert.deepEqual(parseExtraToColumnExtra("generated by default as identity", "opengauss"), {}); assert.deepEqual(parseExtraToColumnExtra("generated by default as identity", "gaussdb"), { identity: { generation: "BY DEFAULT" }, }); @@ -304,6 +303,12 @@ test("parses PostgreSQL extra string to ColumnExtra", () => { }); }); +test("does not expose unsupported identity properties for openGauss", () => { + assert.equal(supportsTableStructureExtendedProperties("opengauss"), false); + assert.equal(supportsTableStructureExtendedProperties("postgres"), true); + assert.equal(supportsTableStructureExtendedProperties("mysql"), true); +}); + test("parses SQL Server identity extra string to ColumnExtra", () => { assert.deepEqual(parseExtraToColumnExtra("identity(1,1)", "sqlserver"), { autoIncrement: true,