From 3119d27c0d3e12b24f203d94b2a109751f615bc8 Mon Sep 17 00:00:00 2001 From: Albert Date: Sun, 9 Nov 2025 19:09:19 +0000 Subject: [PATCH] fix: Correct SurrealDB record creation to use table+ID array format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SurrealDB JavaScript client was interpreting "node:uuid" as a table name instead of a record ID, creating separate schemaless tables for each node. Changed from: db.create("node:uuid", data) To: db.create(['node', 'uuid'], data) This ensures nodes are created as records in the main 'node' table with the specified UUID, not as separate tables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/api/nodes/route.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/api/nodes/route.ts b/app/api/nodes/route.ts index 7ba26ec..ddbd857 100644 --- a/app/api/nodes/route.ts +++ b/app/api/nodes/route.ts @@ -1,6 +1,7 @@ import { NextRequest, NextResponse } from 'next/server'; import { cookies } from 'next/headers'; import { RichText, Agent } from '@atproto/api'; +import { RecordId } from 'surrealdb'; import { connectToDB } from '@/lib/db'; import { generateEmbedding } from '@/lib/ai'; import { verifySurrealJwt } from '@/lib/auth/jwt'; @@ -43,7 +44,8 @@ export async function POST(request: NextRequest) { const createdAt = new Date().toISOString(); // Generate a unique node ID upfront (we'll use this for the detail page link) - const nodeId = `node:${crypto.randomUUID()}`; + const nodeUuid = crypto.randomUUID(); + const nodeId = `node:${nodeUuid}`; const detailUrl = `${process.env.NEXT_PUBLIC_APP_URL || 'https://ponderants.app'}/galaxy/${encodeURIComponent(nodeId)}`; // --- Step 1: Write to Source of Truth (ATproto) --- @@ -235,7 +237,9 @@ export async function POST(request: NextRequest) { nodeData.embedding = embedding; } - const newNode = await db.create(nodeId, nodeData); + // Use RecordId object to specify table and ID separately + // SurrealDB client expects RecordId object, not 'table:id' string + const newNode = await db.create(new RecordId('node', nodeUuid), nodeData); // Handle linking if (links && links.length > 0) {