feat(db): phase 1a — native code-KG schema + 15→16 migration#203
Merged
Conversation
…, #199) Add code_files / code_nodes / code_edges tables and code_nodes_fts external-content FTS5 index to the schema. Append MIGRATIONS[15] as a minimal capability gate (user_version >= 16 = "native KG present"). Tests cover fresh-install, v8-through-16 upgrade path, FK cascade/SET NULL semantics, and no-project-column on edges. - §9-C2: code_edges carries no project column; scope inherits via src_id - §9-C3: resolved predicate is dst_id IS NOT NULL, never provenance - §9-C1: migration test uses v8 fixture (live DB is at v8, not v15) - §9-C6: migration comment describes one try/catch (not per-statement) - G8: migration slices FTS DDL from FTS_SCHEMA.code_nodes (no drift) - G6: FTS_SCHEMA entry auto-wires repair/doctor with zero extra code Closes #199
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lands the native code knowledge graph schema as Phase 1a (epic #196). This is the first of three Phase 1 PRs; 1b (indexer command) and 1c (scout integration) build directly on this schema.
Three files changed, all additive — no existing behavior altered.
Changes
src/db/schema.tscode_files,code_nodes,code_edgesCREATE TABLE IF NOT EXISTStoCREATE_TABLES(fresh-install + existing-install idempotent path viainitDb, G1/G7 precedent)code_nodesentry toFTS_SCHEMA— external-content FTS5 over(name, qualified_name, signature), byte-aligned with the house pattern. Auto-wiresrecall repair/doctorviaFTS_SOURCESwith zero extra code (G6)CREATE_INDEXES, including a partial index on unresolved edges (WHERE dst_id IS NULL) that makes the resolution re-link pass cheapsrc/db/migrations.tsMIGRATIONS[15]— minimal 15→16 capability gate. Body slices FTS DDL fromFTS_SCHEMA.code_nodes(G8 no-drift idiom, same pattern as 14→15). Does NOT open its own transaction (runner provides it). Does NOT re-CREATE base tables (initDb'sCREATE_TABLESalready guarantees them on every init)tests/db/migrations.test.ts+tests/db/schema.test.tscode-KG schema migration (15 to 16)describe block with 4 tests:code_edgescarries noprojectcolumn (§9-C2)src_idCASCADE,dst_idSET NULL — exercised with real inserts/deletes (§9-C3)MIGRATIONS.lengthmutation guards from 15 → 16§9 RedTeam corrections implemented
code_edgeshas noprojectcolumnsrc_iddst_id IS NOT NULLVerification
bun run buildandbun testboth green. Pre-existing failures inopencode-integrationandpi-integration(labeled[RED]— unimplemented hardening tests unrelated to schema/migration) are unchanged.The new describe block contributes 11 tests (37 total in
migrations.test.ts, up from 26).Closes #199