feat(history): record truncate, empty, and drop SQL from table actions
This commit is contained in:
1 parent
238cf81370
commit
a9990d5fdb
7 files changed
+526
-7
No files matched your search
@@ -24,6 +24,7 @@ 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 { recordTableMutationHistory, type TableMutationHistoryStore } from "@/lib/history/tableMutationHistory";
|
||||
import {
|
||||
sidebarDangerTarget,
|
||||
sidebarDangerRunningExecutionId,
|
||||
@@ -57,6 +58,7 @@ interface SidebarTableMutationRuntimeOptions {
|
||||
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>;
|
||||
historyStore?: TableMutationHistoryStore;
|
||||
}
|
||||
|
||||
export function useSidebarTableMutationRuntime(options: SidebarTableMutationRuntimeOptions) {
|
||||
@@ -458,9 +460,13 @@ export function useSidebarTableMutationRuntime(options: SidebarTableMutationRunt
|
||||
const { node, buildSql, onSuccess } = config;
|
||||
if (!node.connectionId || node.database == null) return;
|
||||
const { executionId, isCancelledBeforeDispatch, markDispatched, wasCancelled, cancelConfirmed, waitForCancelConfirmation, markHandedOff } = beginDangerRunningExecution(node.label);
|
||||
const start = Date.now();
|
||||
let executedSql = "";
|
||||
let successRecorded = false;
|
||||
try {
|
||||
await connectionStore.ensureConnected(node.connectionId);
|
||||
const sql = await buildSql();
|
||||
executedSql = sql;
|
||||
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) {
|
||||
@@ -469,6 +475,18 @@ export function useSidebarTableMutationRuntime(options: SidebarTableMutationRunt
|
||||
endDangerRunningExecution();
|
||||
return;
|
||||
}
|
||||
if (options.historyStore) {
|
||||
await recordTableMutationHistory(options.historyStore, {
|
||||
connectionId: node.connectionId,
|
||||
connectionName: connectionStore.getConfig(node.connectionId)?.name,
|
||||
database: node.database,
|
||||
sql,
|
||||
elapsedMs: Date.now() - start,
|
||||
success: true,
|
||||
target: node.label,
|
||||
}).catch((err) => console.warn("[DBX] failed to record table mutation history", err));
|
||||
successRecorded = true;
|
||||
}
|
||||
await onSuccess(node);
|
||||
endDangerRunningExecution();
|
||||
} catch (error: any) {
|
||||
@@ -476,6 +494,18 @@ export function useSidebarTableMutationRuntime(options: SidebarTableMutationRunt
|
||||
const backendError = normalizeBackendError(error) ?? undefined;
|
||||
const cancellationWasRequested = wasCancelled();
|
||||
const cancellationWasConfirmed = cancelConfirmed() || (cancellationWasRequested && (await waitForCancelConfirmation()));
|
||||
if (executedSql && !successRecorded && options.historyStore && !cancellationWasRequested && !cancellationWasConfirmed && !isCancelledBeforeDispatch()) {
|
||||
await recordTableMutationHistory(options.historyStore, {
|
||||
connectionId: node.connectionId,
|
||||
connectionName: connectionStore.getConfig(node.connectionId)?.name,
|
||||
database: node.database,
|
||||
sql: executedSql,
|
||||
elapsedMs: Date.now() - start,
|
||||
success: false,
|
||||
error: message,
|
||||
target: node.label,
|
||||
}).catch((err) => console.warn("[DBX] failed to record table mutation history", err));
|
||||
}
|
||||
toastDangerOperationError(node.label, message, cancellationWasRequested, cancellationWasConfirmed, backendError);
|
||||
if (cancellationWasConfirmed || !isQueryTimeoutErrorMessage(message, backendError)) {
|
||||
endDangerRunningExecution();
|
||||
|
||||
Reference in new issue
Block a user