feat(sidebar): preview and confirm MongoDB database creation

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-08-30 09:59:12 +08:00
1 parent eafc0b2b17
commit 5a11b8f148
3 files changed
+56 -13

No files matched your search

@@ -8,6 +8,7 @@ import {
mongoCollectionKindFromNode,
mongoCollectionTableTypeFromNode,
mongoCloneCollectionPreview,
mongoCreateDatabasePreview,
mongoCreateIndexFormFromRow,
mongoCreateIndexRequestFromSpec,
mongoCreateIndexPreview,
@@ -118,6 +119,10 @@ describe("isProtectedMongoIndex", () => {
});
describe("mongo shell previews", () => {
it("shows the initialization collection used to materialize a database", () => {
expect(mongoCreateDatabasePreview('app "primary"')).toBe('db.getSiblingDB("app \\"primary\\"").createCollection("dbx_init");');
});
it("preserves identifier whitespace in rename preview", () => {
expect(mongoRenameCollectionPreview("app", " users ", " renamed ")).toBe('db.getSiblingDB("app").getCollection(" users ").renameCollection(" renamed ")');
});
@@ -66,6 +66,11 @@ export function mongoCollectionTableTypeFromNode(node: Pick<TreeNode, "meta">):
return kind === "view" ? "VIEW" : kind === "timeseries" ? "TIMESERIES" : "TABLE";
}
/** MongoDB materializes a database when its initialization collection is created. */
export function mongoCreateDatabasePreview(database: string): string {
return `db.getSiblingDB(${JSON.stringify(database)}).createCollection("dbx_init");`;
}
export function toMongoCollectionKind(kind?: string | null): MongoCollectionKind {
const normalized = (kind || "collection").toLowerCase();
if (normalized === "view") return "view";