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): keep tables editable after refresh when index metadata fails
Loc Nguyen90fbc7a5693b
diff --git a/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridActions.spec.tsindex e425db6813..d3db2a8e9a 100644--- a/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts@@ -231,6 +231,27 @@ describe("useDataGridActions", () => {await vi.waitFor(() => expect(tab.tableMetaPending).toBe(false));});+ it("keeps a table editable after manual refresh when index metadata fails but its columns declare the key (#13473)", async () => {+ mocks.getConfig.mockReturnValue({ id: "kingbase-1", db_type: "kingbase" });+ const idColumn = { name: "TitleId", data_type: "int", is_nullable: false, column_default: null, is_primary_key: true, extra: null };+ const tab = tableDataTab({+ connectionId: "kingbase-1",+ tableMeta: { schema: "dbo", tableName: "Title", tableType: "TABLE", columns: [idColumn], primaryKeys: ["TitleId"] },+ });+ mocks.tabs.push(tab);+ mocks.getColumns.mockResolvedValue([idColumn]);+ mocks.listIndexes.mockRejectedValue(new Error("index catalog unavailable"));+ const actions = useDataGridActions(computed(() => tab));++ await actions.onReloadData(tab.id, tab.sql, "", "", "", 100, 0, "refresh");+ // The background index refresh runs after the reload returns; let it settle first.+ await vi.waitFor(() => expect(mocks.listIndexes).toHaveBeenCalled());+ await new Promise((resolve) => setTimeout(resolve, 0));++ expect(tab.tableMeta?.primaryKeys).toEqual(["TitleId"]);+ expect(tab.tableMetaPending).toBe(false);+ });+it.each([true, false])("keeps a surviving old key read-only until index discovery settles (success=%s)", async (success) => {const tab = reactive(tableDataTab());mocks.tabs.push(tab);diff --git a/apps/desktop/src/composables/useDataGridActions.ts b/apps/desktop/src/composables/useDataGridActions.tsindex 7684c9c6c4..bc49b499c7 100644--- a/apps/desktop/src/composables/useDataGridActions.ts+++ b/apps/desktop/src/composables/useDataGridActions.ts@@ -245,7 +245,10 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)columns: metadata.columns,primaryKeys: metadata.primaryKeys,...(metadata.virtualPrimaryKeys?.length ? { virtualPrimaryKeys: metadata.virtualPrimaryKeys } : {}),- rowIdentityResolved: metadata.rowIdentityResolved !== false,+ // A failed index load leaves rowIdentityResolved false (and uncached), but keys the+ // columns already declare still identify rows; only a keyless table needs the+ // unique-index fallback. Otherwise the tab stays read-only after Refresh (#13473).+ rowIdentityResolved: metadata.rowIdentityResolved !== false || metadata.primaryKeys.length > 0,};})();const columns = loaded.columns;