feat(mongodb): bson dumps and database backup/restore

This commit is contained in:
Hand Sonic authored and GitHub committed 2026-09-16 22:46:48 +08:00
1 parent ecc1135de3
commit f5673ca0a1
54 files changed
+6355 -106

No files matched your search

@@ -11,6 +11,7 @@ function setup(node: Partial<TreeNode>, options: { treeNodes?: TreeNode[]; selec
diagramSource: null as unknown,
databaseExportSource: null as unknown,
mongoImportSource: undefined as unknown,
mongoDatabaseDumpSource: null as unknown,
schemaDiffSource: null as unknown,
treeNodes: options.treeNodes ?? [],
selectedTreeNodeIds: options.selectedTreeNodeIds ?? [],
@@ -129,6 +130,29 @@ describe("useSidebarTreeToolRuntime mongo import", () => {
});
});
describe("useSidebarTreeToolRuntime MongoDB dump and restore", () => {
it.each(["dump", "restore"] as const)("opens %s for the selected MongoDB database", (mode) => {
const { connectionStore, runtime } = setup({ type: "mongo-db", connectionId: "conn-1", database: "shop" });
runtime.openMongoDatabaseDump(mode);
expect(connectionStore.mongoDatabaseDumpSource).toEqual({ connectionId: "conn-1", database: "shop", mode });
});
it.each<Partial<TreeNode>>([
{ type: "table", connectionId: "conn-1", database: "shop" },
{ type: "mongo-collection", connectionId: "conn-1", database: "shop" },
{ type: "mongo-db", database: "shop" },
{ type: "mongo-db", connectionId: "conn-1" },
])("does not open a database restore from an invalid context: %j", (node) => {
const { connectionStore, runtime } = setup(node);
runtime.openMongoDatabaseDump("restore");
expect(connectionStore.mongoDatabaseDumpSource).toBeNull();
});
});
describe("useSidebarTreeToolRuntime openSchemaDiffForRoutine", () => {
it("prefills schema diff with a signature-aware routine key", () => {
const { connectionStore, runtime } = setup({