feat(mongo): add dropIndex and dropIndexes support across full stack

This commit is contained in:
onenewcode authored and GitHub committed 2026-07-01 17:53:09 +08:00
1 parent bb72a58e54
commit 93eeeaa9c6
29 files changed
+1142 -24

No files matched your search

+105
View File
@@ -1999,6 +1999,111 @@ test("mongo createIndex execution uses the dedicated create-index endpoint", asy
}
});
test("mongo dropIndex execution uses the dedicated drop-indexes endpoint", async () => {
const restoreStorage = installMemoryStorage();
setActivePinia(createPinia());
const connectionStore = useConnectionStore();
const store = useQueryStore();
const originalFetch = globalThis.fetch;
let dropIndexesBody: any;
connectionStore.addEphemeralConnection({
...conn("mongo-1"),
db_type: "mongodb",
port: 27017,
});
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
const url = String(input);
if (url === "/api/query/prepare-pagination-plan") {
const body = JSON.parse(String(init?.body ?? "{}"));
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
if (url === "/api/mongo/drop-indexes") {
dropIndexesBody = JSON.parse(String(init?.body ?? "{}"));
return new Response(JSON.stringify({ dropped_names: ["users_email_unique"], affected_rows: 1 }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
return new Response("unexpected request", { status: 500 });
});
try {
const tabId = store.createTab("mongo-1", "accounting", "Query", "query", "");
await store.executeTabSql(tabId, 'db.users.dropIndex("users_email_unique")');
const tab = store.tabs.find((item) => item.id === tabId);
assert.deepEqual(dropIndexesBody, {
connectionId: "mongo-1",
database: "accounting",
collection: "users",
indexesJson: '"users_email_unique"',
single: true,
});
assert.deepEqual(tab?.result?.columns, ["name"]);
assert.deepEqual(tab?.result?.rows, [["users_email_unique"]]);
} finally {
globalThis.fetch = originalFetch;
restoreStorage();
}
});
test("mongo dropIndexes execution returns dropped index names", async () => {
const restoreStorage = installMemoryStorage();
setActivePinia(createPinia());
const connectionStore = useConnectionStore();
const store = useQueryStore();
const originalFetch = globalThis.fetch;
let dropIndexesBody: any;
connectionStore.addEphemeralConnection({
...conn("mongo-1"),
db_type: "mongodb",
port: 27017,
});
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
const url = String(input);
if (url === "/api/query/prepare-pagination-plan") {
const body = JSON.parse(String(init?.body ?? "{}"));
return new Response(JSON.stringify({ sqlToExecute: body.options.sql, useAgentResultSession: false }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
if (url === "/api/mongo/drop-indexes") {
dropIndexesBody = JSON.parse(String(init?.body ?? "{}"));
return new Response(JSON.stringify({ dropped_names: ["a_1", "b_1"], affected_rows: 2 }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
}
return new Response("unexpected request", { status: 500 });
});
try {
const tabId = store.createTab("mongo-1", "accounting", "Query", "query", "");
await store.executeTabSql(tabId, "db.users.dropIndexes()");
const tab = store.tabs.find((item) => item.id === tabId);
assert.deepEqual(dropIndexesBody, {
connectionId: "mongo-1",
database: "accounting",
collection: "users",
single: false,
});
assert.deepEqual(tab?.result?.columns, ["name"]);
assert.deepEqual(tab?.result?.rows, [["a_1"], ["b_1"]]);
} finally {
globalThis.fetch = originalFetch;
restoreStorage();
}
});
test("table data export fetches every filtered page", async () => {
const restoreStorage = installMemoryStorage();
setActivePinia(createPinia());