feat(postgres): add table vacuum action
This commit is contained in:
1 parent
0e0edcd206
commit
11407b537f
23 files changed
+554
-36
No files matched your search
@@ -61,7 +61,7 @@ import { codeMirrorSqlDialect } from "@/lib/database/jdbcDialect";
|
||||
import { sqlFormatDialectForDbType } from "@/lib/sql/sqlFormatter";
|
||||
import { createSidebarActionTarget, findSidebarActionTarget, matchesSidebarActionTarget, type SidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";
|
||||
import { syncSidebarTreeNodeExpansion } from "@/lib/sidebar/sidebarTreeExpansion";
|
||||
import type { SidebarDangerDialogRequest } from "@/lib/sidebar/sidebarDangerDialog";
|
||||
import type { SidebarDangerDialogOption, SidebarDangerDialogRequest } from "@/lib/sidebar/sidebarDangerDialog";
|
||||
import { resetSidebarTreeDialogState, sidebarDangerRunningExecutionId } from "./sidebarTreeDialogState";
|
||||
import { SidebarDangerConfirmDialog, SidebarDdlViewDialog, SidebarObjectSourceDialog, SidebarProcedureExecutionDialog, SidebarVisibleDatabasesDialog, SidebarVisibleNacosNamespacesDialog, SidebarVisibleSchemasDialog } from "./sidebarAsyncDialogs";
|
||||
import { sortConnectionListForDisplay } from "@/lib/sidebar/connectionListSort";
|
||||
@@ -1609,8 +1609,9 @@ async function confirmSidebarDangerDialog() {
|
||||
if (!request || sidebarDangerDialogConfirming.value) return;
|
||||
if (request.closeOnConfirm !== false) sidebarDangerDialogOpen.value = false;
|
||||
sidebarDangerDialogConfirming.value = true;
|
||||
let completed: void | boolean = undefined;
|
||||
try {
|
||||
await request.confirm();
|
||||
completed = await request.confirm();
|
||||
} finally {
|
||||
// A danger operation that hit a client-observed timeout is kept alive
|
||||
// (still cancellable) rather than settled outright — sidebarDangerRunningExecutionId
|
||||
@@ -1620,7 +1621,7 @@ async function confirmSidebarDangerDialog() {
|
||||
// execution actually settles.
|
||||
if (!sidebarDangerRunningExecutionId.value) {
|
||||
sidebarDangerDialogConfirming.value = false;
|
||||
sidebarDangerDialogOpen.value = false;
|
||||
if (completed !== false) sidebarDangerDialogOpen.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1651,8 +1652,8 @@ async function cancelSidebarDangerDialogRunning() {
|
||||
}
|
||||
}
|
||||
|
||||
function updateSidebarDangerDialogOption(event: Event) {
|
||||
const option = sidebarDangerDialogRequest.value?.option;
|
||||
function updateSidebarDangerDialogOption(event: Event, optionOverride?: SidebarDangerDialogOption) {
|
||||
const option = optionOverride ?? sidebarDangerDialogRequest.value?.option;
|
||||
if (!option) return;
|
||||
option.checked = (event.target as HTMLInputElement).checked;
|
||||
void option.onChange?.(option.checked);
|
||||
@@ -2490,6 +2491,17 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });
|
||||
<div class="h-full bg-primary transition-[width] duration-200" :style="{ width: `${Math.round((sidebarDangerDialogRequest.progress.completed / sidebarDangerDialogRequest.progress.total) * 100)}%` }" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="sidebarDangerDialogRequest.options?.length" class="mb-3 flex flex-wrap gap-2">
|
||||
<template v-for="(option, optionIndex) in sidebarDangerDialogRequest.options ?? []" :key="`danger-option-${optionIndex}`">
|
||||
<label class="flex items-start gap-2 rounded-md border px-3 py-2 text-sm" :class="[option.compact ? 'min-w-32 flex-1' : 'w-full', option.danger && option.checked ? 'border-destructive/50 bg-destructive/10' : 'bg-muted/20']" :title="option.compact ? option.hint : undefined">
|
||||
<input :checked="option.checked" :disabled="sidebarDangerDialogConfirming" type="checkbox" class="mt-0.5 h-3.5 w-3.5 shrink-0" :class="option.danger ? 'accent-destructive' : 'accent-primary'" @change="updateSidebarDangerDialogOption($event, option)" />
|
||||
<span class="grid gap-0.5">
|
||||
<span class="font-medium" :class="option.danger && option.checked ? 'text-destructive' : 'text-foreground'">{{ option.label }}</span>
|
||||
<span v-if="!option.compact" class="text-xs leading-5 text-muted-foreground">{{ option.hint }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</template>
|
||||
</div>
|
||||
<label v-if="sidebarDangerDialogRequest.option" class="mb-3 flex items-start gap-2 rounded-md border bg-muted/20 px-3 py-2 text-sm">
|
||||
<input :checked="sidebarDangerDialogRequest.option.checked" type="checkbox" class="mt-0.5 h-3.5 w-3.5 shrink-0 accent-primary" @change="updateSidebarDangerDialogOption" />
|
||||
<span class="grid gap-0.5">
|
||||
|
||||
@@ -197,6 +197,7 @@ import {
|
||||
isLoadingStructurePreview,
|
||||
showEmptyTableConfirm,
|
||||
showTruncateTableConfirm,
|
||||
showVacuumTableConfirm,
|
||||
showMysqlAutoIncrementConfirm,
|
||||
showRenameObjectDialog,
|
||||
renameObjectName,
|
||||
@@ -208,6 +209,10 @@ import {
|
||||
emptyTablePreviewSql,
|
||||
truncateTablePreviewSql,
|
||||
truncateTableCascade,
|
||||
vacuumTableFull,
|
||||
vacuumTableAnalyze,
|
||||
vacuumTablePreviewSql,
|
||||
vacuumTableExecuting,
|
||||
mysqlAutoIncrementValue,
|
||||
mysqlAutoIncrementPreviewSql,
|
||||
dropObjectPreviewSql,
|
||||
@@ -510,6 +515,7 @@ const {
|
||||
const {
|
||||
isTableNotView,
|
||||
supportsTruncate,
|
||||
supportsVacuum,
|
||||
supportsMysqlAutoIncrement,
|
||||
canDropTableCascade,
|
||||
canTruncateTableCascade,
|
||||
@@ -522,6 +528,9 @@ const {
|
||||
confirmEmptyTable,
|
||||
truncateTable,
|
||||
confirmTruncateTable,
|
||||
vacuumTable,
|
||||
refreshVacuumPreviewForOptions,
|
||||
confirmVacuumTable,
|
||||
mysqlAutoIncrement,
|
||||
refreshMysqlAutoIncrementPreviewSql,
|
||||
confirmMysqlAutoIncrement,
|
||||
@@ -3945,7 +3954,7 @@ function dangerRequest(request: Omit<SidebarDangerDialogRequest, "target">): Sid
|
||||
const confirm = request.confirm;
|
||||
routedRequest.confirm = async () => {
|
||||
activateActionTarget(target);
|
||||
await confirm();
|
||||
return confirm();
|
||||
};
|
||||
if (request.option?.onChange) {
|
||||
const onChange = request.option.onChange;
|
||||
@@ -3954,6 +3963,14 @@ function dangerRequest(request: Omit<SidebarDangerDialogRequest, "target">): Sid
|
||||
await onChange(checked);
|
||||
};
|
||||
}
|
||||
for (const option of request.options ?? []) {
|
||||
if (!option.onChange) continue;
|
||||
const onChange = option.onChange;
|
||||
option.onChange = async (checked) => {
|
||||
activateActionTarget(target);
|
||||
await onChange(checked);
|
||||
};
|
||||
}
|
||||
if (request.textInput?.onInput) {
|
||||
const onInput = request.textInput.onInput;
|
||||
request.textInput.onInput = async (value) => {
|
||||
@@ -4062,6 +4079,49 @@ routeDangerDialog(showTruncateTableConfirm, () =>
|
||||
}),
|
||||
);
|
||||
|
||||
routeDangerDialog(showVacuumTableConfirm, () =>
|
||||
dangerRequest({
|
||||
title: t("contextMenu.vacuumTableTitle"),
|
||||
message: t("contextMenu.vacuumTableMessage", { name: activeNode.value.label }),
|
||||
get detailsText() {
|
||||
if (vacuumTableExecuting.value) return t("contextMenu.vacuumTableRunningHint");
|
||||
return vacuumTableFull.value ? t("contextMenu.vacuumTableFullRisk") : vacuumTableAnalyze.value ? t("contextMenu.vacuumTableAnalyzeRisk") : t("contextMenu.vacuumTableDefaultRisk");
|
||||
},
|
||||
get sql() {
|
||||
return vacuumTablePreviewSql.value;
|
||||
},
|
||||
get confirmLabel() {
|
||||
return vacuumTableExecuting.value ? t("contextMenu.vacuumTableRunning") : vacuumTableFull.value ? t("contextMenu.vacuumTableFullConfirm") : t("contextMenu.vacuumTable");
|
||||
},
|
||||
loading: false,
|
||||
closeOnConfirm: false,
|
||||
options: [
|
||||
{
|
||||
checked: vacuumTableAnalyze.value,
|
||||
label: t("contextMenu.vacuumTableAnalyze"),
|
||||
hint: t("contextMenu.vacuumTableAnalyzeHint"),
|
||||
compact: true,
|
||||
async onChange(checked) {
|
||||
vacuumTableAnalyze.value = checked;
|
||||
await refreshVacuumPreviewForOptions();
|
||||
},
|
||||
},
|
||||
{
|
||||
checked: vacuumTableFull.value,
|
||||
label: t("contextMenu.vacuumTableFull"),
|
||||
hint: t("contextMenu.vacuumTableFullHint"),
|
||||
compact: true,
|
||||
danger: true,
|
||||
async onChange(checked) {
|
||||
vacuumTableFull.value = checked;
|
||||
await refreshVacuumPreviewForOptions();
|
||||
},
|
||||
},
|
||||
],
|
||||
confirm: confirmVacuumTable,
|
||||
}),
|
||||
);
|
||||
|
||||
routeDangerDialog(showMysqlAutoIncrementConfirm, () =>
|
||||
dangerRequest({
|
||||
title: t("contextMenu.mysqlAutoIncrementTitle"),
|
||||
@@ -5178,6 +5238,9 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
|
||||
items.push({ label: t("contextMenu.duplicateStructure"), action: duplicateStructure, icon: CopyPlus });
|
||||
// Keep menu copy aligned with keyboard copy so frozen multi-selection and single-row fallback stay compatible.
|
||||
items.push(...treeTableClipboardMenuItems(node));
|
||||
if (supportsVacuum.value) {
|
||||
destructiveActions.push({ label: t("contextMenu.vacuumTable"), action: vacuumTable, icon: Activity, variant: "destructive" as const });
|
||||
}
|
||||
if (supportsMysqlAutoIncrement.value) {
|
||||
items.push({ label: t("contextMenu.mysqlAutoIncrement"), action: mysqlAutoIncrement, icon: Gauge });
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ export const structureDocCopyTitle = ref("");
|
||||
export const isLoadingStructurePreview = ref(false);
|
||||
export const showEmptyTableConfirm = ref(false);
|
||||
export const showTruncateTableConfirm = ref(false);
|
||||
export const showVacuumTableConfirm = ref(false);
|
||||
export const showMysqlAutoIncrementConfirm = ref(false);
|
||||
export const showRenameObjectDialog = ref(false);
|
||||
export const renameObjectName = ref("");
|
||||
@@ -48,6 +49,11 @@ export const batchDropCascade = ref(false);
|
||||
export const emptyTablePreviewSql = ref("");
|
||||
export const truncateTablePreviewSql = ref("");
|
||||
export const truncateTableCascade = ref(false);
|
||||
export const vacuumTableFull = ref(false);
|
||||
export const vacuumTableAnalyze = ref(false);
|
||||
export const vacuumTablePreviewSql = ref("");
|
||||
export const vacuumTablePreviewKey = ref("");
|
||||
export const vacuumTableExecuting = ref(false);
|
||||
export const mysqlAutoIncrementValue = ref("1");
|
||||
export const mysqlAutoIncrementPreviewSql = ref("");
|
||||
export const mysqlAutoIncrementPreviewKey = ref("");
|
||||
@@ -187,6 +193,7 @@ const openFlags = [
|
||||
showStructureDocCopyDialog,
|
||||
showEmptyTableConfirm,
|
||||
showTruncateTableConfirm,
|
||||
showVacuumTableConfirm,
|
||||
showMysqlAutoIncrementConfirm,
|
||||
showDropObjectConfirm,
|
||||
showRenameObjectDialog,
|
||||
@@ -230,6 +237,7 @@ export function resetSidebarTreeDialogState() {
|
||||
cloneMongoCollectionLoading.value = false;
|
||||
resetMongoCreateIndexForm();
|
||||
resetMongoIndexManager();
|
||||
vacuumTableExecuting.value = false;
|
||||
sidebarTreeDialogOwner.value = null;
|
||||
sidebarDangerTarget.value = null;
|
||||
sidebarFormTarget.value = null;
|
||||
|
||||
Reference in new issue
Block a user