fix(sidebar): keep destructive table operations cancellable
This commit is contained in:
1 parent
dd77817c7e
commit
89e0f1734b
20 files changed
+627
-25
No files matched your search
+206
-4
@@ -1,7 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { shallowRef } from "vue";
|
||||
import type { TreeNode } from "@/types/database";
|
||||
import { dropTableCascade, dropTablePreviewSql, emptyTablePreviewSql, sidebarDangerTarget, truncateTableCascade, truncateTablePreviewSql } from "@/components/sidebar/sidebarTreeDialogState";
|
||||
import { dropTableCascade, dropTablePreviewSql, emptyTablePreviewSql, sidebarDangerRunningCancel, sidebarDangerRunningExecutionId, sidebarDangerTarget, truncateTableCascade, truncateTablePreviewSql } from "@/components/sidebar/sidebarTreeDialogState";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
toast: vi.fn(),
|
||||
@@ -14,6 +14,7 @@ const mocks = vi.hoisted(() => ({
|
||||
refreshMutatedTableDataTabsForNode: vi.fn(),
|
||||
removeTreeNode: vi.fn(),
|
||||
releaseActiveNodeReference: vi.fn(),
|
||||
cancelQuery: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
||||
@@ -24,6 +25,7 @@ vi.mock("@/lib/database/dbAdminSql", async (importOriginal) => ({
|
||||
buildEmptyTableSql: mocks.buildEmptyTableSql,
|
||||
buildTruncateTableSql: mocks.buildTruncateTableSql,
|
||||
}));
|
||||
vi.mock("@/lib/backend/api", () => ({ cancelQuery: mocks.cancelQuery }));
|
||||
|
||||
import { useSidebarTableMutationRuntime } from "@/composables/useSidebarTableMutationRuntime";
|
||||
|
||||
@@ -71,13 +73,19 @@ describe("useSidebarTableMutationRuntime SAP HANA schema-scoped actions", () =>
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
sidebarDangerTarget.value = null;
|
||||
sidebarDangerRunningExecutionId.value = "";
|
||||
sidebarDangerRunningCancel.value = null;
|
||||
dropTablePreviewSql.value = "";
|
||||
emptyTablePreviewSql.value = "";
|
||||
truncateTablePreviewSql.value = "";
|
||||
dropTableCascade.value = false;
|
||||
truncateTableCascade.value = false;
|
||||
mocks.ensureConnected.mockResolvedValue(undefined);
|
||||
mocks.executeWithProductionGuard.mockResolvedValue(undefined);
|
||||
// A non-undefined result models the real executeWithProductionGuard
|
||||
// resolving to whatever execute() returned (a QueryResult); it only
|
||||
// resolves to `undefined` when the user declines the production-safety
|
||||
// confirmation — see the dedicated "declines" test below.
|
||||
mocks.executeWithProductionGuard.mockResolvedValue({});
|
||||
mocks.refreshMutatedTableDataTabsForNode.mockResolvedValue(undefined);
|
||||
mocks.buildDropTableSql.mockResolvedValue('DROP TABLE "APP"."ORDERS";');
|
||||
mocks.buildEmptyTableSql.mockResolvedValue('DELETE FROM "APP"."ORDERS";');
|
||||
@@ -94,7 +102,13 @@ describe("useSidebarTableMutationRuntime SAP HANA schema-scoped actions", () =>
|
||||
expect(builder).toHaveBeenCalledOnce();
|
||||
expect(builder).toHaveBeenCalledWith({ databaseType: "saphana", schema: "APP", tableName: "ORDERS" });
|
||||
expect(mocks.executeWithProductionGuard).toHaveBeenCalledOnce();
|
||||
expect(mocks.executeWithProductionGuard).toHaveBeenCalledWith(node, sql, { database: "", schema: "APP" });
|
||||
expect(mocks.executeWithProductionGuard).toHaveBeenCalledWith(node, sql, {
|
||||
database: "",
|
||||
schema: "APP",
|
||||
executionId: expect.any(String),
|
||||
isCancelledBeforeDispatch: expect.any(Function),
|
||||
markDispatched: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
it("removes the dropped table and releases its active reference", async () => {
|
||||
@@ -120,7 +134,13 @@ describe("useSidebarTableMutationRuntime SAP HANA schema-scoped actions", () =>
|
||||
|
||||
await feature[action]();
|
||||
|
||||
expect(mocks.executeWithProductionGuard).toHaveBeenCalledWith(node, sql, { database: "TENANT", schema: "APP" });
|
||||
expect(mocks.executeWithProductionGuard).toHaveBeenCalledWith(node, sql, {
|
||||
database: "TENANT",
|
||||
schema: "APP",
|
||||
executionId: expect.any(String),
|
||||
isCancelledBeforeDispatch: expect.any(Function),
|
||||
markDispatched: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
it.each([null, undefined])("rejects a %s database context", async (database) => {
|
||||
@@ -158,4 +178,186 @@ describe("useSidebarTableMutationRuntime SAP HANA schema-scoped actions", () =>
|
||||
expect(mocks.refreshMutatedTableDataTabsForNode).not.toHaveBeenCalled();
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationFailed", 5000);
|
||||
});
|
||||
|
||||
it("registers a running-execution cancel handler while empty table is in flight, and clears it afterward", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async () => {
|
||||
expect(sidebarDangerRunningExecutionId.value).not.toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeTypeOf("function");
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
|
||||
expect(sidebarDangerRunningExecutionId.value).toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeNull();
|
||||
});
|
||||
|
||||
it("shows a timed-out (not failed) toast when the query is still running server-side, and keeps the cancel handle alive", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async (_node: unknown, _sql: unknown, options: { markDispatched: () => void }) => {
|
||||
options.markDispatched();
|
||||
throw new Error("Query timed out after 60 seconds");
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationTimedOut", 8000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationFailed", 5000);
|
||||
// A client-observed timeout must not remove the user's ability to cancel
|
||||
// — the underlying operation may still be running on the database.
|
||||
expect(sidebarDangerRunningExecutionId.value).not.toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeTypeOf("function");
|
||||
});
|
||||
|
||||
it("classifies a JDBC-agent-routed timeout (SAP HANA/Oracle/DB2/SQL Server) as timed-out, not failed, even though its message has no timeout wording", async () => {
|
||||
const { feature } = runtime("");
|
||||
// AgentCallError::Timeout carries no `detail` (crates/dbx-core/src/backend_error.rs),
|
||||
// so BackendErrorException.message degrades to a generic fallback with no
|
||||
// "timed out" text — only the structured backendError distinguishes it.
|
||||
const agentTimeoutError = {
|
||||
name: "BackendErrorException",
|
||||
message: "Backend request failed",
|
||||
backendError: {
|
||||
version: 1,
|
||||
code: "DBX-JDBC-2001",
|
||||
messageKey: "backendErrors.jdbc.operationTimedOut",
|
||||
messageParams: { stage: "execute" },
|
||||
source: "jdbcAgent",
|
||||
operationOutcome: "unknown",
|
||||
},
|
||||
};
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async (_node: unknown, _sql: unknown, options: { markDispatched: () => void }) => {
|
||||
options.markDispatched();
|
||||
throw agentTimeoutError;
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationTimedOut", 8000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationFailed", 5000);
|
||||
// The cancel entry point must stay live for this database family too.
|
||||
expect(sidebarDangerRunningExecutionId.value).not.toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeTypeOf("function");
|
||||
});
|
||||
|
||||
it("shows a cancelled toast when the user explicitly cancels the running query", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.cancelQuery.mockResolvedValueOnce(true);
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async (_node: unknown, _sql: unknown, options: { markDispatched: () => void }) => {
|
||||
options.markDispatched();
|
||||
await sidebarDangerRunningCancel.value?.();
|
||||
throw new Error("Query timed out after 60 seconds");
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
|
||||
expect(mocks.cancelQuery).toHaveBeenCalledOnce();
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationCancelled", 3000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationTimedOut", 8000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationFailed", 5000);
|
||||
expect(sidebarDangerRunningExecutionId.value).toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeNull();
|
||||
});
|
||||
|
||||
it("never dispatches the SQL when the user cancels before the operation is sent to the database (registration race)", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.ensureConnected.mockImplementationOnce(async () => {
|
||||
// The user clicks Cancel Query while we're still waiting on the
|
||||
// connection — well before the backend has any executionId to
|
||||
// register, let alone cancel.
|
||||
await sidebarDangerRunningCancel.value?.();
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
|
||||
expect(mocks.executeWithProductionGuard).not.toHaveBeenCalled();
|
||||
expect(mocks.cancelQuery).not.toHaveBeenCalled();
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationCancelled", 3000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationFailed", 5000);
|
||||
expect(sidebarDangerRunningExecutionId.value).toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeNull();
|
||||
});
|
||||
|
||||
it("does not report a false 'cancelled' outcome when the backend never confirms the cancel", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.cancelQuery.mockResolvedValue(false);
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async (_node: unknown, _sql: unknown, options: { markDispatched: () => void }) => {
|
||||
options.markDispatched();
|
||||
await sidebarDangerRunningCancel.value?.();
|
||||
throw new Error("some backend error unrelated to timeout");
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
|
||||
// Bounded retry, not a single silently-ignored attempt.
|
||||
expect(mocks.cancelQuery.mock.calls.length).toBeGreaterThan(1);
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationCancelUnconfirmed", 8000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationCancelled", 3000);
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationFailed", 5000);
|
||||
expect(sidebarDangerRunningExecutionId.value).toBe("");
|
||||
});
|
||||
|
||||
it("lets a cancel confirmed after a timeout finish closing out the running execution", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async (_node: unknown, _sql: unknown, options: { markDispatched: () => void }) => {
|
||||
options.markDispatched();
|
||||
throw new Error("Query timed out after 60 seconds");
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
expect(sidebarDangerRunningExecutionId.value).not.toBe("");
|
||||
mocks.toast.mockClear();
|
||||
|
||||
// The dialog's Cancel Query button is still wired to the same handle;
|
||||
// the user clicks it after the timeout and the backend now confirms it.
|
||||
mocks.cancelQuery.mockResolvedValueOnce(true);
|
||||
await sidebarDangerRunningCancel.value?.();
|
||||
|
||||
expect(mocks.toast).toHaveBeenCalledWith("contextMenu.tableOperationCancelled", 3000);
|
||||
expect(sidebarDangerRunningExecutionId.value).toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeNull();
|
||||
});
|
||||
|
||||
it("does not let the cancel handle hang forever if cancelQuery itself never resolves", async () => {
|
||||
const { feature } = runtime("");
|
||||
mocks.executeWithProductionGuard.mockImplementationOnce(async (_node: unknown, _sql: unknown, options: { markDispatched: () => void }) => {
|
||||
options.markDispatched();
|
||||
throw new Error("Query timed out after 60 seconds");
|
||||
});
|
||||
|
||||
await feature.confirmEmptyTable();
|
||||
expect(sidebarDangerRunningExecutionId.value).not.toBe("");
|
||||
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
// A wedged connection: cancelQuery never settles at all.
|
||||
mocks.cancelQuery.mockImplementation(() => new Promise(() => {}));
|
||||
const cancelPromise = sidebarDangerRunningCancel.value?.();
|
||||
// CANCEL_QUERY_OVERALL_TIMEOUT_MS is 10s; advance past it.
|
||||
await vi.advanceTimersByTimeAsync(11_000);
|
||||
await cancelPromise;
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
// The closure above must have settled instead of hanging — a stuck
|
||||
// cancel handle would otherwise permanently disable the shared
|
||||
// sidebarDangerDialogCancelling state for every future danger dialog.
|
||||
expect(mocks.toast).not.toHaveBeenCalledWith("contextMenu.tableOperationCancelled", 3000);
|
||||
});
|
||||
|
||||
it.each(actions)("does not report a false success for $action when the user declines the production-safety confirmation", async ({ action }) => {
|
||||
const { feature } = runtime("");
|
||||
mocks.executeWithProductionGuard.mockResolvedValueOnce(undefined);
|
||||
|
||||
await feature[action]();
|
||||
|
||||
expect(mocks.toast).not.toHaveBeenCalled();
|
||||
expect(mocks.closeDroppedTableObjectTabsForNode).not.toHaveBeenCalled();
|
||||
expect(mocks.removeTreeNode).not.toHaveBeenCalled();
|
||||
expect(mocks.releaseActiveNodeReference).not.toHaveBeenCalled();
|
||||
expect(mocks.refreshMutatedTableDataTabsForNode).not.toHaveBeenCalled();
|
||||
expect(sidebarDangerRunningExecutionId.value).toBe("");
|
||||
expect(sidebarDangerRunningCancel.value).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -6,8 +6,14 @@ import type { DatabaseType, TreeNode } from "@/types/database";
|
||||
import { supportsTableTruncate } from "@/lib/database/databaseCapabilities";
|
||||
import { buildDropTableSql, buildEmptyTableSql, buildMysqlAutoIncrementSql, buildTruncateTableSql, supportsDropTableCascade, supportsNativeMysqlAutoIncrement, supportsTruncateTableCascade, type MysqlAutoIncrementSqlOptions, type TableAdminSqlOptions } from "@/lib/database/dbAdminSql";
|
||||
import { isSqlServerLinkedNode } from "@/lib/database/sqlServerLinkedServers";
|
||||
import { isQueryTimeoutErrorMessage } from "@/lib/sql/queryError";
|
||||
import { uuid } from "@/lib/common/utils";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { normalizeBackendError, type BackendError } from "@/lib/backend/errorUtils";
|
||||
import {
|
||||
sidebarDangerTarget,
|
||||
sidebarDangerRunningExecutionId,
|
||||
sidebarDangerRunningCancel,
|
||||
showDropTableConfirm,
|
||||
showEmptyTableConfirm,
|
||||
showMysqlAutoIncrementConfirm,
|
||||
@@ -28,7 +34,7 @@ interface SidebarTableMutationRuntimeOptions {
|
||||
connectionStore: ReturnType<typeof useConnectionStore>;
|
||||
currentDatabaseType: () => DatabaseType | undefined;
|
||||
databaseTypeForNode: (node: TreeNode) => DatabaseType | undefined;
|
||||
executeWithProductionGuard: (node: Pick<TreeNode, "connectionId" | "database" | "schema">, sql: string, options?: { database?: string; schema?: string }) => Promise<unknown>;
|
||||
executeWithProductionGuard: (node: Pick<TreeNode, "connectionId" | "database" | "schema">, sql: string, options?: { database?: string; schema?: string; executionId?: string; isCancelledBeforeDispatch?: () => boolean; markDispatched?: () => void }) => Promise<unknown>;
|
||||
closeDroppedTableObjectTabsForNode: (node: TreeNode) => void;
|
||||
refreshMutatedTableDataTabsForNode: (node: TreeNode) => Promise<void>;
|
||||
}
|
||||
@@ -151,19 +157,134 @@ export function useSidebarTableMutationRuntime(options: SidebarTableMutationRunt
|
||||
await connectionStore.refreshObjectListTreeNode(node.connectionId, node.database, node.schema);
|
||||
}
|
||||
|
||||
// Bounded, undelayed retry: register_task on the backend runs as the very
|
||||
// first statement of the execute_query command, so if cancelQuery races a
|
||||
// just-dispatched execution, a couple of retries are enough for the
|
||||
// registration to land — no artificial delay needed.
|
||||
const CANCEL_QUERY_MAX_ATTEMPTS = 5;
|
||||
// Overall cap on the whole retry sequence, mirroring queryStore.ts's
|
||||
// withCancelQueryTimeout/CANCEL_QUERY_TIMEOUT_MS for the main editor. If
|
||||
// api.cancelQuery itself hangs (e.g. a wedged connection), the retry loop
|
||||
// alone would never settle, which would permanently disable every future
|
||||
// danger dialog's Cancel Query button (sidebarDangerDialogCancelling is a
|
||||
// shared singleton — see ConnectionTree.vue).
|
||||
const CANCEL_QUERY_OVERALL_TIMEOUT_MS = 10_000;
|
||||
|
||||
async function confirmCancelWithRetry(executionId: string): Promise<boolean> {
|
||||
for (let attempt = 0; attempt < CANCEL_QUERY_MAX_ATTEMPTS; attempt++) {
|
||||
let confirmed = false;
|
||||
try {
|
||||
confirmed = await api.cancelQuery(executionId);
|
||||
} catch {
|
||||
confirmed = false;
|
||||
}
|
||||
if (confirmed) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function confirmCancelWithRetryAndTimeout(executionId: string): Promise<boolean> {
|
||||
const timeout = new Promise<boolean>((resolve) => {
|
||||
setTimeout(() => resolve(false), CANCEL_QUERY_OVERALL_TIMEOUT_MS);
|
||||
});
|
||||
return Promise.race([confirmCancelWithRetry(executionId), timeout]);
|
||||
}
|
||||
|
||||
const DANGER_OPERATION_CANCELLED_BEFORE_DISPATCH_MESSAGE = "Operation cancelled before it was sent to the database.";
|
||||
|
||||
interface DangerRunningExecution {
|
||||
executionId: string;
|
||||
isCancelledBeforeDispatch: () => boolean;
|
||||
markDispatched: () => void;
|
||||
wasCancelled: () => boolean;
|
||||
cancelConfirmed: () => boolean;
|
||||
markHandedOff: () => void;
|
||||
}
|
||||
|
||||
function beginDangerRunningExecution(nodeLabel: string): DangerRunningExecution {
|
||||
const executionId = uuid();
|
||||
let dispatched = false;
|
||||
let cancelledByUser = false;
|
||||
let cancelConfirmedFlag = false;
|
||||
// Set once the owning confirm*Table() call has already given up waiting
|
||||
// (a client-observed timeout) and deferred final cleanup to a later
|
||||
// confirmed cancel — see markHandedOff below.
|
||||
let handedOff = false;
|
||||
|
||||
sidebarDangerRunningExecutionId.value = executionId;
|
||||
sidebarDangerRunningCancel.value = async () => {
|
||||
cancelledByUser = true;
|
||||
// Nothing has reached the backend yet: the pending dispatch will see
|
||||
// isCancelledBeforeDispatch() and skip the network call entirely, so
|
||||
// this is already a confirmed cancellation.
|
||||
const confirmed = dispatched ? await confirmCancelWithRetryAndTimeout(executionId) : true;
|
||||
if (confirmed) cancelConfirmedFlag = true;
|
||||
if (handedOff && confirmed && sidebarDangerRunningExecutionId.value === executionId) {
|
||||
toast(t("contextMenu.tableOperationCancelled", { name: nodeLabel }), 3000);
|
||||
endDangerRunningExecution();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
executionId,
|
||||
isCancelledBeforeDispatch: () => cancelledByUser && !dispatched,
|
||||
markDispatched: () => {
|
||||
dispatched = true;
|
||||
},
|
||||
wasCancelled: () => cancelledByUser,
|
||||
cancelConfirmed: () => cancelConfirmedFlag,
|
||||
markHandedOff: () => {
|
||||
handedOff = true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function endDangerRunningExecution() {
|
||||
sidebarDangerRunningExecutionId.value = "";
|
||||
sidebarDangerRunningCancel.value = null;
|
||||
}
|
||||
|
||||
function toastDangerOperationError(name: string, message: string, wasCancelled: boolean, cancelConfirmed: boolean, backendError?: BackendError) {
|
||||
if (cancelConfirmed) {
|
||||
toast(t("contextMenu.tableOperationCancelled", { name }), 3000);
|
||||
} else if (wasCancelled) {
|
||||
toast(t("contextMenu.tableOperationCancelUnconfirmed", { name, message }), 8000);
|
||||
} else if (isQueryTimeoutErrorMessage(message, backendError)) {
|
||||
toast(t("contextMenu.tableOperationTimedOut", { name, message }), 8000);
|
||||
} else {
|
||||
toast(t("contextMenu.tableOperationFailed", { message }), 5000);
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDropTable() {
|
||||
const node = sidebarDangerTarget.value ?? activeNode.value;
|
||||
if (!node.connectionId || node.database == null) return;
|
||||
const { executionId, isCancelledBeforeDispatch, markDispatched, wasCancelled, cancelConfirmed, markHandedOff } = beginDangerRunningExecution(node.label);
|
||||
try {
|
||||
await connectionStore.ensureConnected(node.connectionId);
|
||||
const sql = dropTablePreviewSql.value || (await buildDropTableSql(tableAdminSqlOptionsForNode(node, { cascade: dropTableCascade.value && supportsDropTableCascade(databaseTypeForNode(node)) })));
|
||||
await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema });
|
||||
if (isCancelledBeforeDispatch()) throw new Error(DANGER_OPERATION_CANCELLED_BEFORE_DISPATCH_MESSAGE);
|
||||
const executed = await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema, executionId, isCancelledBeforeDispatch, markDispatched });
|
||||
if (executed === undefined) {
|
||||
// The user declined the production-safety confirmation: the SQL was
|
||||
// never sent, so this must not be reported as a successful drop.
|
||||
endDangerRunningExecution();
|
||||
return;
|
||||
}
|
||||
toast(t("contextMenu.dropTableSuccess", { name: node.label }), 3000);
|
||||
options.closeDroppedTableObjectTabsForNode(node);
|
||||
connectionStore.removeTreeNode(node.id);
|
||||
options.releaseActiveNodeReference([node.id]);
|
||||
endDangerRunningExecution();
|
||||
} catch (error: any) {
|
||||
toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);
|
||||
const message = error?.message || String(error);
|
||||
const backendError = normalizeBackendError(error) ?? undefined;
|
||||
toastDangerOperationError(node.label, message, wasCancelled(), cancelConfirmed(), backendError);
|
||||
if (cancelConfirmed() || !isQueryTimeoutErrorMessage(message, backendError)) {
|
||||
endDangerRunningExecution();
|
||||
} else {
|
||||
markHandedOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,15 +296,31 @@ export function useSidebarTableMutationRuntime(options: SidebarTableMutationRunt
|
||||
async function confirmEmptyTable() {
|
||||
const node = sidebarDangerTarget.value ?? activeNode.value;
|
||||
if (!node.connectionId || node.database == null) return;
|
||||
const { executionId, isCancelledBeforeDispatch, markDispatched, wasCancelled, cancelConfirmed, markHandedOff } = beginDangerRunningExecution(node.label);
|
||||
try {
|
||||
await connectionStore.ensureConnected(node.connectionId);
|
||||
const sql = emptyTablePreviewSql.value || (await buildEmptyTableSql(tableAdminSqlOptionsForNode(node)));
|
||||
await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema });
|
||||
if (isCancelledBeforeDispatch()) throw new Error(DANGER_OPERATION_CANCELLED_BEFORE_DISPATCH_MESSAGE);
|
||||
const executed = await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema, executionId, isCancelledBeforeDispatch, markDispatched });
|
||||
if (executed === undefined) {
|
||||
// The user declined the production-safety confirmation: the SQL was
|
||||
// never sent, so this must not be reported as a successful empty.
|
||||
endDangerRunningExecution();
|
||||
return;
|
||||
}
|
||||
const messageKey = databaseTypeForNode(node) === "clickhouse" ? "contextMenu.emptyTableSubmitted" : "contextMenu.emptyTableSuccess";
|
||||
toast(t(messageKey, { name: node.label }), 3000);
|
||||
await options.refreshMutatedTableDataTabsForNode(node);
|
||||
endDangerRunningExecution();
|
||||
} catch (error: any) {
|
||||
toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);
|
||||
const message = error?.message || String(error);
|
||||
const backendError = normalizeBackendError(error) ?? undefined;
|
||||
toastDangerOperationError(node.label, message, wasCancelled(), cancelConfirmed(), backendError);
|
||||
if (cancelConfirmed() || !isQueryTimeoutErrorMessage(message, backendError)) {
|
||||
endDangerRunningExecution();
|
||||
} else {
|
||||
markHandedOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,14 +333,30 @@ export function useSidebarTableMutationRuntime(options: SidebarTableMutationRunt
|
||||
async function confirmTruncateTable() {
|
||||
const node = sidebarDangerTarget.value ?? activeNode.value;
|
||||
if (!node.connectionId || node.database == null) return;
|
||||
const { executionId, isCancelledBeforeDispatch, markDispatched, wasCancelled, cancelConfirmed, markHandedOff } = beginDangerRunningExecution(node.label);
|
||||
try {
|
||||
await connectionStore.ensureConnected(node.connectionId);
|
||||
const sql = truncateTablePreviewSql.value || (await buildTruncateTableSql(tableAdminSqlOptionsForNode(node, { cascade: truncateTableCascade.value && supportsTruncateTableCascade(databaseTypeForNode(node)) })));
|
||||
await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema });
|
||||
if (isCancelledBeforeDispatch()) throw new Error(DANGER_OPERATION_CANCELLED_BEFORE_DISPATCH_MESSAGE);
|
||||
const executed = await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema, executionId, isCancelledBeforeDispatch, markDispatched });
|
||||
if (executed === undefined) {
|
||||
// The user declined the production-safety confirmation: the SQL was
|
||||
// never sent, so this must not be reported as a successful truncate.
|
||||
endDangerRunningExecution();
|
||||
return;
|
||||
}
|
||||
toast(t("contextMenu.truncateTableSuccess", { name: node.label }), 3000);
|
||||
await options.refreshMutatedTableDataTabsForNode(node);
|
||||
endDangerRunningExecution();
|
||||
} catch (error: any) {
|
||||
toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);
|
||||
const message = error?.message || String(error);
|
||||
const backendError = normalizeBackendError(error) ?? undefined;
|
||||
toastDangerOperationError(node.label, message, wasCancelled(), cancelConfirmed(), backendError);
|
||||
if (cancelConfirmed() || !isQueryTimeoutErrorMessage(message, backendError)) {
|
||||
endDangerRunningExecution();
|
||||
} else {
|
||||
markHandedOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user