fix(transfer): distinguish explicit empty object selection from default
This commit is contained in:
1 parent
d43ba11164
commit
609f6805a3
12 files changed
+705
-241
No files matched your search
@@ -4,7 +4,7 @@ import { uuid } from "@/lib/common/utils";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { buildTransferObjectSelections, countTransferObjects } from "./transferSelections";
|
||||
import { buildTransferObjectSelectionField, countTransferObjects } from "./transferSelections";
|
||||
import { createTaskLoadTracker } from "./taskLoadTracker";
|
||||
import { describeTransferStructureOperation, summarizeTransferStructureOperations } from "./structurePlanSummary";
|
||||
import {
|
||||
@@ -812,7 +812,7 @@ async function requestStartTransfer() {
|
||||
tables: [...selectedTables.value],
|
||||
createTable: transferContent.value !== "dataOnly",
|
||||
content: transferContent.value,
|
||||
objects: buildTransferObjectSelections(selectedObjects.value, treeDisabledGroups.value),
|
||||
...buildTransferObjectSelectionField(selectedObjects.value, treeDisabledGroups.value),
|
||||
...transferStrategyOptions(targetTableStrategy.value),
|
||||
targetTableNameCase: targetTableNameCase.value,
|
||||
quoteTargetColumnNames: quoteTargetColumnNames.value,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildTransferObjectSelections, countTransferObjects, matchBulkObjectNames, parseBulkObjectNames } from "../transferSelections";
|
||||
import { buildTransferObjectSelectionField, buildTransferObjectSelections, countTransferObjects, matchBulkObjectNames, parseBulkObjectNames } from "../transferSelections";
|
||||
|
||||
function setOf(names: string[]): Set<string> {
|
||||
return new Set(names);
|
||||
@@ -44,6 +44,23 @@ describe("buildTransferObjectSelections", () => {
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps an explicit empty objects field for a saved TABLE-only request", () => {
|
||||
const request = {
|
||||
tables: ["orders"],
|
||||
...buildTransferObjectSelectionField({ TABLE: setOf(["orders"]) }, []),
|
||||
};
|
||||
expect(Object.hasOwn(request, "objects")).toBe(true);
|
||||
expect(request.objects).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps only the non-table selection for a saved TABLE + VIEW request", () => {
|
||||
const request = {
|
||||
tables: ["orders"],
|
||||
...buildTransferObjectSelectionField({ TABLE: setOf(["orders"]), VIEW: setOf(["v_orders"]) }, []),
|
||||
};
|
||||
expect(request.objects).toEqual([{ objectType: "VIEW", names: ["v_orders"] }]);
|
||||
});
|
||||
|
||||
it("filters disabled object types even when stale selections remain", () => {
|
||||
const result = buildTransferObjectSelections(
|
||||
{
|
||||
|
||||
@@ -17,6 +17,10 @@ export function countTransferObjects(request: Pick<TransferRequest, "tables" | "
|
||||
* cross-family matrix does not allow) are dropped at the request boundary
|
||||
* even if stale selections are still present in the tree.
|
||||
*/
|
||||
export function buildTransferObjectSelectionField(selectedObjects: Partial<Record<TransferObjectKind, Set<string>>>, disabledGroups: TransferObjectKind[]): { objects: TransferObjectSelectionPayload[] } {
|
||||
return { objects: buildTransferObjectSelections(selectedObjects, disabledGroups) };
|
||||
}
|
||||
|
||||
export function buildTransferObjectSelections(selectedObjects: Partial<Record<TransferObjectKind, Set<string>>>, disabledGroups: TransferObjectKind[]): TransferObjectSelectionPayload[] {
|
||||
return (Object.keys(selectedObjects) as TransferObjectKind[])
|
||||
.filter((kind) => kind !== "TABLE" && !disabledGroups.includes(kind))
|
||||
|
||||
@@ -67,6 +67,39 @@ describe("transferTaskStore", () => {
|
||||
expect(store.listTasks("folder-1").map((task) => task.id)).toEqual(["task-1"]);
|
||||
});
|
||||
|
||||
it("normalizes a legacy task with no object selection to an empty modern selection map", async () => {
|
||||
const legacyConfig = makeConfig() as Partial<TransferTaskConfig>;
|
||||
delete legacyConfig.objects;
|
||||
vi.mocked(api.loadTransferTaskLibrary).mockResolvedValue({
|
||||
version: 1,
|
||||
folders: [],
|
||||
tasks: [{ id: "legacy-selection", name: "legacy selection", config: legacyConfig }],
|
||||
} as unknown as TransferTaskLibrary);
|
||||
|
||||
const store = useTransferTaskStore();
|
||||
await store.initFromStorage();
|
||||
|
||||
expect(store.getTask("legacy-selection")?.config.objects).toEqual({});
|
||||
});
|
||||
|
||||
it("round-trips TABLE-only and TABLE + VIEW task selections", async () => {
|
||||
const store = useTransferTaskStore();
|
||||
const tableOnly = await store.saveTask({ name: "table-only", config: makeConfig({ objects: { TABLE: ["orders"] } }) });
|
||||
const tableAndView = await store.saveTask({
|
||||
name: "table-and-view",
|
||||
config: makeConfig({ objects: { TABLE: ["orders"], VIEW: ["v_orders"] } }),
|
||||
});
|
||||
const persisted = vi.mocked(api.saveTransferTaskLibrary).mock.calls.at(-1)?.[0] as TransferTaskLibrary;
|
||||
|
||||
vi.mocked(api.loadTransferTaskLibrary).mockResolvedValue(persisted);
|
||||
setActivePinia(createPinia());
|
||||
const reloadedStore = useTransferTaskStore();
|
||||
await reloadedStore.initFromStorage();
|
||||
|
||||
expect(reloadedStore.getTask(tableOnly.id)?.config.objects).toEqual({ TABLE: ["orders"] });
|
||||
expect(reloadedStore.getTask(tableAndView.id)?.config.objects).toEqual({ TABLE: ["orders"], VIEW: ["v_orders"] });
|
||||
});
|
||||
|
||||
it("keeps target column quoting enabled for saved tasks created before the option existed", async () => {
|
||||
const legacyConfig = makeConfig() as Partial<TransferTaskConfig>;
|
||||
delete legacyConfig.quoteTargetColumnNames;
|
||||
|
||||
Reference in new issue
Block a user