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

Function init_schema

src/store/store.c:228–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226/* ── Schema ─────────────────────────────────────────────────────── */
227
228static int init_schema(cbm_store_t *s) {
229 const char *ddl =
230 "CREATE TABLE IF NOT EXISTS projects ("
231 " name TEXT PRIMARY KEY,"
232 " indexed_at TEXT NOT NULL,"
233 " root_path TEXT NOT NULL"
234 ");"
235 "CREATE TABLE IF NOT EXISTS file_hashes ("
236 " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
237 " rel_path TEXT NOT NULL,"
238 " sha256 TEXT NOT NULL,"
239 " mtime_ns INTEGER NOT NULL DEFAULT 0,"
240 " size INTEGER NOT NULL DEFAULT 0,"
241 " PRIMARY KEY (project, rel_path)"
242 ");"
243 "CREATE TABLE IF NOT EXISTS nodes ("
244 " id INTEGER PRIMARY KEY AUTOINCREMENT,"
245 " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
246 " label TEXT NOT NULL,"
247 " name TEXT NOT NULL,"
248 " qualified_name TEXT NOT NULL,"
249 " file_path TEXT DEFAULT '',"
250 " start_line INTEGER DEFAULT 0,"
251 " end_line INTEGER DEFAULT 0,"
252 " properties TEXT DEFAULT '{}',"
253 " UNIQUE(project, qualified_name)"
254 ");"
255 /* local_name_gen (#768): IMPORTS edges carry one imported symbol's
256 * local_name each, so uniqueness must discriminate on it — two named
257 * imports from the same specifier are distinct edges. Non-IMPORTS
258 * edges get '' (NOT NULL: NULLs never conflict in a UNIQUE index,
259 * which would break their dedup entirely). Mirrors the graph-buffer
260 * dedup key (make_edge_key) and the raw dump writer's DDL + hand-
261 * built sqlite_autoindex_edges_1 (internal/cbm/sqlite_writer.c) —
262 * keep all three in sync. */
263 "CREATE TABLE IF NOT EXISTS edges ("
264 " id INTEGER PRIMARY KEY AUTOINCREMENT,"
265 " project TEXT NOT NULL REFERENCES projects(name) ON DELETE CASCADE,"
266 " source_id INTEGER NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,"
267 " target_id INTEGER NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,"
268 " type TEXT NOT NULL,"
269 " properties TEXT DEFAULT '{}',"
270 " url_path_gen TEXT GENERATED ALWAYS AS (json_extract(properties,'$.url_path')),"
271 " local_name_gen TEXT GENERATED ALWAYS AS (CASE WHEN type='IMPORTS'"
272 " THEN coalesce(json_extract(properties,'$.local_name'),'') ELSE '' END),"
273 " UNIQUE(source_id, target_id, type, local_name_gen)"
274 ");"
275 "CREATE TABLE IF NOT EXISTS project_summaries ("
276 " project TEXT PRIMARY KEY,"
277 " summary TEXT NOT NULL,"
278 " source_hash TEXT NOT NULL,"
279 " created_at TEXT NOT NULL,"
280 " updated_at TEXT NOT NULL"
281 ");"
282 /* One row per file: its serialized cross-file LSP surface + the
283 * closure-repair metadata (surface hash, referenced-name bloom,
284 * governing-config context). Written at publication from exactly the
285 * def set pass_lsp_cross registered, so an incremental run can

Callers 1

store_open_internalFunction · 0.85

Calls 1

exec_sqlFunction · 0.85

Tested by

no test coverage detected