fix(kingbase): preserve query schema context

This commit is contained in:
zipg authored and GitHub committed 2026-07-29 18:43:53 +08:00
1 parent 51ab6fb9ec
commit 02aea73d28
6 files changed
+306 -49

No files matched your search

@@ -85,6 +85,10 @@ describe("query execution schema", () => {
expect(connectionQueryExecutionSchema({ db_type: "postgres" }, "app", "reporting", false)).toBe("reporting");
});
it("prefers an explicit schema for Kingbase query execution", () => {
expect(connectionQueryExecutionSchema({ db_type: "kingbase" }, "qinzhou", "sdy_smartsite", false)).toBe("sdy_smartsite");
});
it("does not send a schema for MySQL database context", () => {
expect(connectionQueryExecutionSchema({ db_type: "mysql" }, "app", undefined, false)).toBeUndefined();
});
@@ -0,0 +1,19 @@
import type { HistoryEntry } from "@/lib/backend/api";
import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";
import type { ConnectionConfig, QueryTab } from "@/types/database";
export interface HistorySqlRestoreTarget {
connectionId: string;
database: string;
schema?: string;
}
export function resolveHistorySqlRestoreTarget(options: { entry: HistoryEntry; activeTab?: QueryTab; firstConnectionId?: string; getConfig: (connectionId: string) => ConnectionConfig | undefined }): HistorySqlRestoreTarget | null {
const { entry, activeTab, firstConnectionId, getConfig } = options;
const connectionId = entry.connection_id || activeTab?.connectionId || firstConnectionId;
if (!connectionId) return null;
const config = getConfig(connectionId);
const database = entry.database || activeTab?.database || (config ? resolveDefaultDatabase(config, []) : "");
const schema = activeTab?.connectionId === connectionId && activeTab.database === database ? activeTab.schema : undefined;
return { connectionId, database: database || "", schema };
}