feat(structure): show table constraints for postgres-compatible dbs
This commit is contained in:
1 parent
7ad05b178f
commit
20a2994fa1
37 files changed
+2725
-156
No files matched your search
@@ -7,6 +7,7 @@ import { useHistoryStore } from "@/stores/historyStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { useProductionSafetyStore } from "@/stores/productionSafetyStore";
|
||||
import * as objectMetadataCache from "@/lib/metadata/objectMetadataCache";
|
||||
import type { ConnectionConfig, QueryTab } from "@/types/database";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
@@ -22,6 +23,11 @@ vi.mock("@/lib/backend/api", () => ({
|
||||
connectionWriteUnlockState: vi.fn().mockResolvedValue(0),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/metadata/objectMetadataCache", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@/lib/metadata/objectMetadataCache")>();
|
||||
return { ...actual, invalidateObjectMetadataCache: vi.fn() };
|
||||
});
|
||||
|
||||
function installLocalStorage() {
|
||||
const data = new Map<string, string>();
|
||||
vi.stubGlobal("localStorage", {
|
||||
@@ -129,6 +135,7 @@ describe("useSqlExecution", () => {
|
||||
beforeEach(() => {
|
||||
installLocalStorage();
|
||||
setActivePinia(createPinia());
|
||||
vi.mocked(objectMetadataCache.invalidateObjectMetadataCache).mockClear();
|
||||
});
|
||||
|
||||
it("invalidates object metadata after successful connection-level DDL", async () => {
|
||||
@@ -158,6 +165,35 @@ describe("useSqlExecution", () => {
|
||||
expect(loadDatabases).toHaveBeenCalledWith("conn-1", { force: true });
|
||||
});
|
||||
|
||||
it("invalidates table facets after successful Kingbase constraint DDL", async () => {
|
||||
const sql = "ALTER TABLE public.orders DISABLE CONSTRAINT orders_check";
|
||||
const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), schema: "public", sql });
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("kingbase"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const queryStore = useQueryStore();
|
||||
const connectionStore = useConnectionStore();
|
||||
useSettingsStore().editorSettings.confirmDangerousSqlExecution = false;
|
||||
vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {
|
||||
if (activeTab.value) activeTab.value.result = { columns: [], rows: [], affected_rows: 0, execution_time_ms: 1 };
|
||||
});
|
||||
vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
|
||||
const invalidateObjectMetadata = vi.mocked(objectMetadataCache.invalidateObjectMetadataCache).mockResolvedValue(undefined);
|
||||
const refreshObjects = vi.spyOn(connectionStore, "refreshObjectListTreeNode").mockResolvedValue(undefined);
|
||||
|
||||
const execution = useSqlExecution({
|
||||
activeTab: computed(() => activeTab.value),
|
||||
activeConnection: computed(() => activeConnection.value),
|
||||
executableSql: computed(() => sql),
|
||||
activeOutputView,
|
||||
requestDangerConfirmation: async () => true,
|
||||
});
|
||||
|
||||
await execution.tryExecute();
|
||||
|
||||
expect(invalidateObjectMetadata).toHaveBeenCalledWith({ connectionId: "conn-1", database: "app", schema: "public" });
|
||||
expect(refreshObjects).toHaveBeenCalledWith("conn-1", "app", "public");
|
||||
});
|
||||
|
||||
it("sends every placeholder syntax and @set unchanged when substitution is disabled", async () => {
|
||||
const sql = ["@set tenant = 42;", "SELECT ?, :named, ${shell}, #{mybatis}, @sqlserver, @tenant;"].join("\n");
|
||||
const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), sql });
|
||||
|
||||
@@ -10,6 +10,7 @@ import { supportsConnectionScopedQueryExecution } from "@/lib/database/databaseF
|
||||
import { supportsConnectionLevelSqlExecution } from "@/lib/connection/connectionLevelDatabaseBootstrap";
|
||||
import { classifySqlActivityKind } from "@/lib/history/historyActivityKind";
|
||||
import { sqlMetadataRefreshTarget } from "@/lib/sql/sqlMetadataRefresh";
|
||||
import { invalidateObjectMetadataCache } from "@/lib/metadata/objectMetadataCache";
|
||||
import { defaultViewForResult } from "@/lib/query/queryResultDefaultView";
|
||||
import { isQueryExecutionErrorResult } from "@/lib/query/queryResultError";
|
||||
import { classifyRedisCommandSafety } from "@/lib/redis/redisCommandSafety";
|
||||
@@ -333,8 +334,10 @@ export function useSqlExecution(deps: {
|
||||
const refreshTarget = sqlMetadataRefreshTarget(sql, tab.schema);
|
||||
if (refreshTarget.scope === "connection") {
|
||||
connectionStore.invalidateMetadataCache(tab.connectionId);
|
||||
await invalidateObjectMetadataCache({ connectionId: tab.connectionId });
|
||||
await connectionStore.loadDatabases(tab.connectionId, { force: true });
|
||||
} else if (refreshTarget.scope === "database") {
|
||||
await invalidateObjectMetadataCache({ connectionId: tab.connectionId, database: tab.database, schema: refreshTarget.schema });
|
||||
await connectionStore.refreshObjectListTreeNode(tab.connectionId, tab.database, refreshTarget.schema);
|
||||
}
|
||||
}
|
||||
@@ -478,8 +481,10 @@ export function useSqlExecution(deps: {
|
||||
const refreshTarget = sqlMetadataRefreshTarget(sql, executionTab.schema);
|
||||
if (refreshTarget.scope === "connection") {
|
||||
connectionStore.invalidateMetadataCache(executionTab.connectionId);
|
||||
await invalidateObjectMetadataCache({ connectionId: executionTab.connectionId });
|
||||
await connectionStore.loadDatabases(executionTab.connectionId, { force: true });
|
||||
} else if (refreshTarget.scope === "database") {
|
||||
await invalidateObjectMetadataCache({ connectionId: executionTab.connectionId, database: executionTab.database, schema: refreshTarget.schema });
|
||||
await connectionStore.refreshObjectListTreeNode(executionTab.connectionId, executionTab.database, refreshTarget.schema);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user