MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / init_schema

Function init_schema

src/store/store.c:327–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327static int init_schema(cbm_store_t *s) {
328 const char *ddl =
329 "CREATE TABLE IF NOT EXISTS projects ("
330 " name TEXT PRIMARY KEY,"
331 " indexed_at TEXT NOT NULL,"
332 " root_path TEXT NOT NULL"
333 ");"
334 "CREATE TABLE IF NOT EXISTS file_hashes ("
335 " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
336 " rel_path TEXT NOT NULL,"
337 " sha256 TEXT NOT NULL,"
338 " mtime_ns INTEGER NOT NULL DEFAULT 0,"
339 " size INTEGER NOT NULL DEFAULT 0,"
340 " PRIMARY KEY (project, rel_path)"
341 ");"
342 "CREATE TABLE IF NOT EXISTS nodes ("
343 " id INTEGER PRIMARY KEY AUTOINCREMENT,"
344 " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
345 " label TEXT NOT NULL,"
346 " name TEXT NOT NULL,"
347 " qualified_name TEXT NOT NULL,"
348 " file_path TEXT DEFAULT '',"
349 " start_line INTEGER DEFAULT 0,"
350 " end_line INTEGER DEFAULT 0,"
351 " properties TEXT DEFAULT '{}',"
352 " UNIQUE(project, qualified_name)"
353 ");"
354 /* local_name_gen (#768): IMPORTS edges carry one imported symbol's
355 * local_name each, so uniqueness must discriminate on it — two named
356 * imports from the same specifier are distinct edges. Non-IMPORTS
357 * edges get '' (NOT NULL: NULLs never conflict in a UNIQUE index,
358 * which would break their dedup entirely). Mirrors the graph-buffer
359 * dedup key (make_edge_key) and the raw dump writer's DDL + hand-
360 * built sqlite_autoindex_edges_1 (internal/cbm/sqlite_writer.c) —
361 * keep all three in sync. */
362 "CREATE TABLE IF NOT EXISTS edges ("
363 " id INTEGER PRIMARY KEY AUTOINCREMENT,"
364 " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
365 " source_id INTEGER NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,"
366 " target_id INTEGER NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,"
367 " type TEXT NOT NULL,"
368 " properties TEXT DEFAULT '{}',"
369 " url_path_gen TEXT GENERATED ALWAYS AS (json_extract(properties,'$.url_path')),"
370 " local_name_gen TEXT GENERATED ALWAYS AS (CASE WHEN type='IMPORTS'"
371 " THEN coalesce(json_extract(properties,'$.local_name'),'') ELSE '' END),"
372 " UNIQUE(source_id, target_id, type, local_name_gen)"
373 ");"
374 "CREATE TABLE IF NOT EXISTS project_summaries ("
375 " project TEXT PRIMARY KEY,"
376 " summary TEXT NOT NULL,"
377 " source_hash TEXT NOT NULL,"
378 " created_at TEXT NOT NULL,"
379 " updated_at TEXT NOT NULL"
380 ");"
381 /* One row per file: its serialized cross-file LSP surface + the
382 * closure-repair metadata (surface hash, referenced-name bloom,
383 * governing-config context). Written at publication from exactly the
384 * def set pass_lsp_cross registered, so an incremental run can

Callers 1

store_open_internalFunction · 0.85

Calls 2

exec_sqlFunction · 0.85

Tested by

no test coverage detected