Skip to content

Commit f07b42e

Browse files
committed
fix: remove string id field definitions, use SurrealDB built-in record ids
BREAKING SCHEMA CHANGE: Fixed incompatibility with SurrealDB 2.3.10 record ID handling by removing manual id field definitions. Root cause: Defining `id` as `string` type overrides SurrealDB's built-in record ID system, preventing proper record queries with FROM/WHERE clauses. Changes: - Removed `id` field definition from nodes table (line 35) - Removed `id` field definition from edges table (line 99) - Removed `id` field definition from symbol_embeddings table (line 216) - Changed fn::node_info() parameter type from `string` to `record` - Simplified fn::node_info() to use record parameter directly In SurrealDB 2.x, `id` is ALWAYS a built-in record type (e.g., nodes:⟨uuid⟩). Defining it as string breaks native record ID functionality. Migration required: 1. Re-apply schema: cd schema && ./apply-schema.sh 2. Re-index codebase: codegraph index -l rust -r --force . After migration, queries work properly: SELECT * FROM nodes:⟨uuid⟩; SELECT fn::node_info(nodes:⟨uuid⟩);
1 parent 87f6f1d commit f07b42e

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

schema/codegraph.surql

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ DEFINE ANALYZER code_analyzer TOKENIZERS BLANK,CLASS FILTERS LOWERCASE,SNOWBALL(
3131
DEFINE TABLE IF NOT EXISTS nodes SCHEMAFULL
3232
COMMENT 'Code entities from AST parsing with semantic embeddings';
3333

34-
-- Core fields (preserved exactly)
35-
DEFINE FIELD IF NOT EXISTS id ON TABLE nodes TYPE string;
34+
-- Core fields (id is built-in record type, no need to define it)
3635
DEFINE FIELD IF NOT EXISTS name ON TABLE nodes TYPE string;
3736
DEFINE FIELD IF NOT EXISTS node_type ON TABLE nodes TYPE option<string>;
3837
DEFINE FIELD IF NOT EXISTS language ON TABLE nodes TYPE option<string>;
@@ -97,7 +96,7 @@ DEFINE INDEX IF NOT EXISTS idx_nodes_file_type ON TABLE nodes COLUMNS file_path,
9796
DEFINE TABLE IF NOT EXISTS edges SCHEMAFULL
9897
COMMENT 'Code relationships (Calls, Imports, Uses, Extends, Implements, References)';
9998

100-
DEFINE FIELD IF NOT EXISTS id ON TABLE edges TYPE string;
99+
-- id is built-in record type, no need to define it
101100
DEFINE FIELD IF NOT EXISTS from ON TABLE edges TYPE record<nodes>;
102101
DEFINE FIELD IF NOT EXISTS to ON TABLE edges TYPE record<nodes>;
103102
DEFINE FIELD IF NOT EXISTS edge_type ON TABLE edges TYPE string;
@@ -214,7 +213,7 @@ DEFINE TABLE IF NOT EXISTS symbol_embeddings SCHEMAFULL
214213
COMMENT 'Cached embeddings for normalized symbols used during edge resolution'
215214
PERMISSIONS FULL;
216215

217-
DEFINE FIELD IF NOT EXISTS id ON symbol_embeddings TYPE string;
216+
-- id is built-in record type, no need to define it
218217
DEFINE FIELD IF NOT EXISTS symbol ON symbol_embeddings TYPE string;
219218
DEFINE FIELD IF NOT EXISTS normalized_symbol ON symbol_embeddings TYPE string;
220219
DEFINE FIELD IF NOT EXISTS project_id ON symbol_embeddings TYPE option<string>;
@@ -293,15 +292,7 @@ DEFINE INDEX IF NOT EXISTS idx_symbol_embeddings_edge
293292
-- -----------------------------------------------------------------------------
294293
-- FUNCTION: node_info (UNCHANGED)
295294
-- -----------------------------------------------------------------------------
296-
DEFINE FUNCTION fn::node_info($node_id: string) {
297-
-- Build full record ID string ("nodes:uuid" format)
298-
LET $full_id = IF string::starts_with($node_id, 'nodes:') THEN
299-
$node_id
300-
ELSE
301-
string::concat('nodes:', $node_id)
302-
END;
303-
304-
-- Cast string to record and query
295+
DEFINE FUNCTION fn::node_info($node_id: record) {
305296
LET $res = SELECT
306297
id,
307298
name,
@@ -314,7 +305,7 @@ DEFINE FUNCTION fn::node_info($node_id: string) {
314305
start_line: start_line,
315306
end_line: end_line
316307
} AS location
317-
FROM ONLY <record> $full_id;
308+
FROM ONLY $node_id;
318309

319310
RETURN $res;
320311
};

0 commit comments

Comments
 (0)