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(grid): support cross database foreign key navigation
lxk95568cfe5b679a6
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex aadaf95d1b..70288f6080 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -13067,6 +13067,8 @@ async function navigateToForeignKeyCell(rowIndex: number, actualColIdx: number)currentSchema: props.tableMeta?.schema || props.schema,fk: association.foreignKey,whereInput: condition,+ connection: connectionStore.getConfig(props.connectionId),+ databaseType: resolvedDatabaseType.value,}),);} catch (e: any) {diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridForeignKeyNavigation.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridForeignKeyNavigation.spec.tsindex dbd10908e6..587f1eb0c1 100644--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridForeignKeyNavigation.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridForeignKeyNavigation.spec.ts@@ -156,4 +156,98 @@ describe("foreignKeyNavigationTarget", () => {const target = foreignKeyNavigationTarget({ connectionId: "c1", database: "db", fk: fk(), whereInput: '"id" = 7' });expect(target.whereInput).toBe('"id" = 7');});++ it("en MySQL navega a la base de datos de ref_schema y vacía schema", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "db_vrent",+ fk: fk({ ref_schema: "other_db", ref_table: "tb_company", ref_column: "id" }),+ databaseType: "mysql",+ });+ expect(target.database).toBe("other_db");+ expect(target.schema).toBeUndefined();+ expect(target.tableName).toBe("tb_company");+ expect(target.columnName).toBe("id");+ });++ it("con conexión nativa MySQL resuelve target.database según ref_schema", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "db_vrent",+ fk: fk({ ref_schema: "other_db", ref_table: "tb_company" }),+ connection: { db_type: "mysql" },+ });+ expect(target.database).toBe("other_db");+ expect(target.schema).toBeUndefined();+ });++ it("en MySQL sin ref_schema mantiene la base de datos actual", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "db_vrent",+ fk: fk({ ref_schema: null, ref_table: "tb_company" }),+ databaseType: "mysql",+ });+ expect(target.database).toBe("db_vrent");+ expect(target.schema).toBeUndefined();+ });++ it("con conexión JDBC MySQL navega a la base de datos de ref_schema", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "db_vrent",+ fk: fk({ ref_schema: "other_db", ref_table: "tb_company" }),+ connection: { db_type: "jdbc", driver_profile: "mysql" },+ });+ expect(target.database).toBe("other_db");+ expect(target.schema).toBeUndefined();+ });++ it("en bases con esquema (PostgreSQL) preserva database y asigna ref_schema como schema", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "app_db",+ currentSchema: "public",+ fk: fk({ ref_schema: "sales", ref_table: "customers" }),+ databaseType: "postgres",+ connection: { db_type: "postgres" },+ });+ expect(target.database).toBe("app_db");+ expect(target.schema).toBe("sales");+ });++ it("con objeto de conexión sin db_type pero databaseType postgres preserva schema", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "app_db",+ currentSchema: "public",+ fk: fk({ ref_schema: "sales", ref_table: "customers" }),+ databaseType: "postgres",+ connection: {},+ });+ expect(target.database).toBe("app_db");+ expect(target.schema).toBe("sales");+ });++ it("en MySQL con ref_schema de espacios en blanco cae a database actual", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "db_vrent",+ fk: fk({ ref_schema: " ", ref_table: "tb_company" }),+ databaseType: "mysql",+ });+ expect(target.database).toBe("db_vrent");+ expect(target.schema).toBeUndefined();+ });++ it("en MySQL con ref_schema con espacios recorta el nombre del destino", () => {+ const target = foreignKeyNavigationTarget({+ connectionId: "c1",+ database: "db_vrent",+ fk: fk({ ref_schema: " other_db ", ref_table: "tb_company" }),+ databaseType: "mysql",+ });+ expect(target.database).toBe("other_db");+ expect(target.schema).toBeUndefined();+ });});diff --git a/apps/desktop/src/lib/dataGrid/dataGridForeignKeyNavigation.ts b/apps/desktop/src/lib/dataGrid/dataGridForeignKeyNavigation.tsindex 2c68a3bcee..2f4d75f504 100644--- a/apps/desktop/src/lib/dataGrid/dataGridForeignKeyNavigation.ts+++ b/apps/desktop/src/lib/dataGrid/dataGridForeignKeyNavigation.ts@@ -1,6 +1,8 @@import type { NavigationTarget } from "@/composables/useNavigationTargets";import type { CellValue } from "@/lib/dataGrid/cellValue";-import type { ForeignKeyInfo } from "@/types/database";+import type { DatabaseType, ForeignKeyInfo } from "@/types/database";+import { isSchemaAware, usesDatabaseObjectTreeMode } from "@/lib/database/databaseFeatureSupport";+import { connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, type JdbcDialectConnection } from "@/lib/database/jdbcDialect";export interface ForeignKeyAssociation {foreignKey: ForeignKeyInfo;@@ -87,9 +89,36 @@ export function foreignKeyMetadataRequestCurrent(options: { requestGeneration: nreturn options.requestGeneration === options.currentGeneration && options.requestIdentity === options.currentIdentity;}-/** 构建跳转到被引用表的导航目标:ref_schema 缺失时回退当前 schema(同 ER 图) */-export function foreignKeyNavigationTarget(options: { connectionId: string; database: string; currentSchema?: string; fk: ForeignKeyInfo; whereInput?: string }): NavigationTarget {- const schema = options.fk.ref_schema || options.currentSchema || undefined;+function isDatabaseTreeHierarchy(options: { connection?: JdbcDialectConnection; databaseType?: DatabaseType }): boolean {+ const type = options.connection ? (effectiveDatabaseTypeForConnection(options.connection) ?? options.databaseType) : options.databaseType;+ if (type) {+ return !isSchemaAware(type) || (options.connection ? connectionUsesDatabaseObjectTreeMode(options.connection) : usesDatabaseObjectTreeMode(type));+ }+ if (options.connection) {+ return connectionUsesDatabaseObjectTreeMode(options.connection);+ }+ return false;+}++/** 构建跳转到被引用表的导航目标:+ * - 仅数据库层级(如 MySQL / 数据库对象树模式):ref_schema 承载目标数据库名,跨库跳转时切至目标库,schema 置空+ * - 模式感知数据库(如 PostgreSQL / SQL Server):database 保持当前库,ref_schema 承载模式名(缺失时回退当前 schema,同 ER 图)+ */+export function foreignKeyNavigationTarget(options: { connectionId: string; database: string; currentSchema?: string; fk: ForeignKeyInfo; whereInput?: string; connection?: JdbcDialectConnection; databaseType?: DatabaseType }): NavigationTarget {+ const isDbTree = isDatabaseTreeHierarchy(options);+ if (isDbTree) {+ const database = options.fk.ref_schema?.trim() || options.database;+ return {+ connectionId: options.connectionId,+ database,+ schema: undefined,+ tableName: options.fk.ref_table,+ columnName: options.fk.ref_column,+ whereInput: options.whereInput,+ };+ }++ const schema = options.fk.ref_schema?.trim() || options.currentSchema || undefined;return {connectionId: options.connectionId,database: options.database,