Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(table): hide unsupported identity column for opengauss

zipgc99c0d932c9d
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<CreateDatabaseCharsetMetadata>();
@@ -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,