feat(compare): keep schema and data compares running in background
This commit is contained in:
1 parent
29c6d1fbed
commit
dc7b905220
15 files changed
+1643
-535
No files matched your search
@@ -2,7 +2,7 @@ import { reactive, computed } from "vue";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { isTerminalTransferProgress } from "@/lib/backend/transferProgress";
|
||||
|
||||
export type BackgroundTaskKind = "table-export" | "database-export" | "sql-file" | "data-transfer" | "multi-db-execution";
|
||||
export type BackgroundTaskKind = "table-export" | "database-export" | "sql-file" | "data-transfer" | "multi-db-execution" | "schema-diff" | "data-compare";
|
||||
export type BackgroundTaskStatus = "Running" | "Writing" | "Cancelling" | "Done" | "Error" | "Cancelled";
|
||||
export type DatabaseExportSource = "manual" | "scheduled";
|
||||
|
||||
@@ -70,7 +70,36 @@ export interface ExportTask {
|
||||
multiDbSkippedCount?: number;
|
||||
multiDbNotExecutedCount?: number;
|
||||
currentTarget?: { connectionId: string; catalog?: string; database: string; schema?: string };
|
||||
comparePhase?: string;
|
||||
compareCurrent?: number;
|
||||
compareTotal?: number;
|
||||
compareCurrentObject?: string;
|
||||
compareResultCount?: number;
|
||||
compareSameCount?: number;
|
||||
compareDifferentCount?: number;
|
||||
compareFailedCount?: number;
|
||||
compareAddedCount?: number;
|
||||
compareRemovedCount?: number;
|
||||
compareModifiedCount?: number;
|
||||
canCancel?: boolean;
|
||||
onOpen?: () => void;
|
||||
onRemove?: () => void;
|
||||
}
|
||||
|
||||
export interface CompareTaskProgress {
|
||||
status: Extract<BackgroundTaskStatus, "Running" | "Done" | "Error" | "Cancelled">;
|
||||
comparePhase?: string;
|
||||
compareCurrent?: number;
|
||||
compareTotal?: number;
|
||||
compareCurrentObject?: string;
|
||||
compareResultCount?: number;
|
||||
compareSameCount?: number;
|
||||
compareDifferentCount?: number;
|
||||
compareFailedCount?: number;
|
||||
compareAddedCount?: number;
|
||||
compareRemovedCount?: number;
|
||||
compareModifiedCount?: number;
|
||||
errorMessage?: string | null;
|
||||
}
|
||||
|
||||
export interface MultiDbExecutionTaskProgress {
|
||||
@@ -458,6 +487,37 @@ export function useExportTracker() {
|
||||
return task;
|
||||
}
|
||||
|
||||
function addCompareTask(kind: "schema-diff" | "data-compare", sessionId: string, label: string, onOpen?: () => void, onRemove?: () => void): ExportTask {
|
||||
const task = reactive<ExportTask>({
|
||||
exportId: sessionId,
|
||||
kind,
|
||||
tableName: label,
|
||||
format: "compare",
|
||||
filePath: "",
|
||||
rowsExported: 0,
|
||||
totalRows: null,
|
||||
status: "Running",
|
||||
errorMessage: null,
|
||||
compareCurrent: 0,
|
||||
compareTotal: 0,
|
||||
compareCurrentObject: "",
|
||||
canCancel: false,
|
||||
onOpen,
|
||||
onRemove,
|
||||
startedAt: Date.now(),
|
||||
});
|
||||
taskMap.set(sessionId, task);
|
||||
return task;
|
||||
}
|
||||
|
||||
function addSchemaDiffTask(sessionId: string, label: string, onOpen?: () => void, onRemove?: () => void): ExportTask {
|
||||
return addCompareTask("schema-diff", sessionId, label, onOpen, onRemove);
|
||||
}
|
||||
|
||||
function addDataCompareTask(sessionId: string, label: string, onOpen?: () => void, onRemove?: () => void): ExportTask {
|
||||
return addCompareTask("data-compare", sessionId, label, onOpen, onRemove);
|
||||
}
|
||||
|
||||
function addMultiDbExecutionTask(batchId: string, label: string, sourceTabId: string, onOpen?: () => void): ExportTask {
|
||||
const task = reactive<ExportTask>({
|
||||
exportId: batchId,
|
||||
@@ -642,7 +702,36 @@ export function useExportTracker() {
|
||||
task.totalRows = progress.totalRows ?? task.totalRows;
|
||||
}
|
||||
|
||||
function updateCompareTask(sessionId: string, progress: CompareTaskProgress): void {
|
||||
const task = taskMap.get(sessionId);
|
||||
if (!task || (task.kind !== "schema-diff" && task.kind !== "data-compare")) return;
|
||||
task.status = progress.status;
|
||||
task.comparePhase = progress.comparePhase;
|
||||
task.compareCurrent = progress.compareCurrent;
|
||||
task.compareTotal = progress.compareTotal;
|
||||
task.compareCurrentObject = progress.compareCurrentObject;
|
||||
task.compareResultCount = progress.compareResultCount;
|
||||
task.compareSameCount = progress.compareSameCount;
|
||||
task.compareDifferentCount = progress.compareDifferentCount;
|
||||
task.compareFailedCount = progress.compareFailedCount;
|
||||
task.compareAddedCount = progress.compareAddedCount;
|
||||
task.compareRemovedCount = progress.compareRemovedCount;
|
||||
task.compareModifiedCount = progress.compareModifiedCount;
|
||||
task.errorMessage = progress.errorMessage ?? null;
|
||||
if (task.status === "Done" || task.status === "Error" || task.status === "Cancelled") finishExportTask(task);
|
||||
}
|
||||
|
||||
function cleanupFinishedTask(task: ExportTask): void {
|
||||
try {
|
||||
task.onRemove?.();
|
||||
} catch {
|
||||
// cleanup hooks must not prevent the task from being removed
|
||||
}
|
||||
}
|
||||
|
||||
function removeTask(exportId: string) {
|
||||
const task = taskMap.get(exportId);
|
||||
if (task && (task.status === "Done" || task.status === "Error" || task.status === "Cancelled")) cleanupFinishedTask(task);
|
||||
taskMap.delete(exportId);
|
||||
taskCancelHandlers.delete(exportId);
|
||||
transferFailureStates.delete(exportId);
|
||||
@@ -652,6 +741,7 @@ export function useExportTracker() {
|
||||
function clearFinished() {
|
||||
for (const [id, task] of taskMap) {
|
||||
if (task.status === "Done" || task.status === "Error" || task.status === "Cancelled") {
|
||||
cleanupFinishedTask(task);
|
||||
taskMap.delete(id);
|
||||
taskCancelHandlers.delete(id);
|
||||
transferFailureStates.delete(id);
|
||||
@@ -670,6 +760,7 @@ export function useExportTracker() {
|
||||
|
||||
async function cancelTask(exportId: string) {
|
||||
const task = taskMap.get(exportId);
|
||||
if (task?.canCancel === false) return;
|
||||
try {
|
||||
const customHandler = taskCancelHandlers.get(exportId);
|
||||
if (customHandler) {
|
||||
@@ -696,6 +787,8 @@ export function useExportTracker() {
|
||||
addDatabaseExportTask,
|
||||
addSqlFileTask,
|
||||
addDataTransferTask,
|
||||
addSchemaDiffTask,
|
||||
addDataCompareTask,
|
||||
addMultiDbExecutionTask,
|
||||
updateMultiDbExecutionTask,
|
||||
startDataTransferTask,
|
||||
@@ -705,6 +798,7 @@ export function useExportTracker() {
|
||||
restoreDatabaseExportTaskRunning,
|
||||
updateSqlFileTask,
|
||||
updateDataTransferTask,
|
||||
updateCompareTask,
|
||||
registerTaskCancelHandler,
|
||||
unregisterTaskCancelHandler,
|
||||
removeTask,
|
||||
|
||||
Reference in new issue
Block a user