fix(table): repair restored PostgreSQL table identity

Closes #10474
This commit is contained in:
t8y2 authored and t8y2 committed 2026-09-29 00:47:45 +08:00
1 parent d49f3739bf
commit 4d85afd173
3 files changed
+87 -10

No files matched your search

+30 -1
View File
@@ -1,4 +1,5 @@
import type { QueryTab, ColumnInfo } from "@/types/database";
import { queryResultSourceNameParts } from "@/lib/sql/queryResultSource";
import type { QueryTab, ColumnInfo, DatabaseType } from "@/types/database";
export type DataTabTableMeta = NonNullable<QueryTab["tableMeta"]>;
@@ -15,6 +16,34 @@ function titleTableName(tab: QueryTab): string {
return title;
}
/**
* Repair the one legacy identity shape known to lose its schema during tab
* restoration. PostgreSQL permits dots inside quoted identifiers, so the tab
* title alone is deliberately not split. The persisted SELECT must independently
* parse to the same schema-qualified source before the identity is migrated.
*/
export function repairRestoredDataTabTableIdentity(tab: QueryTab, databaseType: DatabaseType | undefined): boolean {
if (databaseType !== "postgres" || tab.mode !== "data" || tab.schema?.trim() || tab.tableMeta?.schema?.trim() || tab.tableMeta?.columns.length) return false;
const sourceSql = tab.resultBaseSql?.trim() || tab.lastExecutedSql?.trim() || tab.sql.trim();
const source = queryResultSourceNameParts(sourceSql, { databaseType });
const title = tab.title.trim();
if (!source?.qualifier || title !== `${source.qualifier}.${source.name}`) return false;
const persistedTableName = tab.tableMeta?.tableName.trim();
if (persistedTableName && persistedTableName !== title && persistedTableName !== source.name) return false;
tab.schema = source.qualifier;
tab.tableMeta = {
...tab.tableMeta,
schema: source.qualifier,
tableName: source.name,
columns: tab.tableMeta?.columns ?? [],
primaryKeys: tab.tableMeta?.primaryKeys ?? [],
};
return true;
}
function fallbackColumnInfo(name: string): ColumnInfo {
return {
name,
+2 -1
View File
@@ -66,7 +66,7 @@ import { usesAgentCursorForQuery, usesAgentCursorForTableData } from "@/lib/data
import { connectionIsDorisFamilyCatalogCapable, defaultAutoCommitForDbType, supportsClearableQuerySchema, supportsTransaction, usesOracleStickyTransactionState, usesProvenReadOnlyStickyTransactionState } from "@/lib/database/databaseFeatureSupport";
import { canInsertTableRows, canUseKeylessRowPredicate, DBX_ROWID_COLUMN, editablePrimaryKeys, shouldIncludeSyntheticRowId, usesSyntheticRowIdKey } from "@/lib/table/tableEditing";
import { TABLE_DATA_EXPORT_PAGE_SIZE } from "@/lib/table/tableDataExport";
import { tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";
import { repairRestoredDataTabTableIdentity, tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";
import { isDataTabMetadataLifecycleStale } from "@/lib/sidebar/dataTabOpenPolicy";
import type { SqlInsertMode } from "@/lib/export/sqlInsertMode";
import { csvNullLiteralForMode } from "@/lib/export/csvNullMode";
@@ -2426,6 +2426,7 @@ export const useQueryStore = defineStore("query", () => {
tab.autoCommit = defaultAutoCommitForDbTypeWithSetting(connection?.db_type);
} else if (tab.mode === "data" && connection) {
tab.schema = connectionObjectTreeNodeSchema(connection, tab.database, tab.schema);
repairRestoredDataTabTableIdentity(tab, effectiveDatabaseTypeForConnection(connection));
}
}
restored.tabs.forEach(initializeResultAutoSave);