diff --git a/src/db.ts b/src/db.ts index 845540c..24cb0a9 100644 --- a/src/db.ts +++ b/src/db.ts @@ -17,6 +17,19 @@ export function getDb(): Database { export async function ensureGraph(): Promise { const db = getDb() + + const nodes = db.collection('nodes') + if (!(await nodes.exists())) { + console.log('Creating collection: nodes') + await db.createCollection('nodes') + } + + const edges = db.collection('edges') + if (!(await edges.exists())) { + console.log('Creating edge collection: edges') + await db.createEdgeCollection('edges') + } + const graphs = await db.listGraphs() if (graphs.some(g => g.name === 'optovia_graph')) return