diff --git a/code-review-graph-vscode/src/backend/sqlite.ts b/code-review-graph-vscode/src/backend/sqlite.ts index 267b3a2..9fead0f 100644 --- a/code-review-graph-vscode/src/backend/sqlite.ts +++ b/code-review-graph-vscode/src/backend/sqlite.ts @@ -208,7 +208,7 @@ export class SqliteReader { if (row) { const version = parseInt(row.value, 10); // Must match LATEST_VERSION in code_review_graph/migrations.py - const SUPPORTED_SCHEMA_VERSION = 6; + const SUPPORTED_SCHEMA_VERSION = 7; if (!isNaN(version) && version > SUPPORTED_SCHEMA_VERSION) { return `Database was created with a newer version (schema v${version}). Update the extension.`; } diff --git a/code_review_graph/graph.py b/code_review_graph/graph.py index 2dfa97f..83841e9 100644 --- a/code_review_graph/graph.py +++ b/code_review_graph/graph.py @@ -70,6 +70,8 @@ CREATE INDEX IF NOT EXISTS idx_edges_source ON edges(source_qualified); CREATE INDEX IF NOT EXISTS idx_edges_target ON edges(target_qualified); CREATE INDEX IF NOT EXISTS idx_edges_kind ON edges(kind); +CREATE INDEX IF NOT EXISTS idx_edges_target_kind ON edges(target_qualified, kind); +CREATE INDEX IF NOT EXISTS idx_edges_source_kind ON edges(source_qualified, kind); CREATE INDEX IF NOT EXISTS idx_edges_file ON edges(file_path); """ diff --git a/code_review_graph/migrations.py b/code_review_graph/migrations.py index ddb446e..06d4d07 100644 --- a/code_review_graph/migrations.py +++ b/code_review_graph/migrations.py @@ -203,6 +203,19 @@ def _migrate_v6(conn: sqlite3.Connection) -> None: "(community_summaries, flow_snapshots, risk_index)") +def _migrate_v7(conn: sqlite3.Connection) -> None: + """v7: Add compound edge indexes for summary and risk queries.""" + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_edges_target_kind " + "ON edges(target_qualified, kind)" + ) + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_edges_source_kind " + "ON edges(source_qualified, kind)" + ) + logger.info("Migration v7: added compound edge indexes") + + # --------------------------------------------------------------------------- # Migration registry # --------------------------------------------------------------------------- @@ -213,6 +226,7 @@ def _migrate_v6(conn: sqlite3.Connection) -> None: 4: _migrate_v4, 5: _migrate_v5, 6: _migrate_v6, + 7: _migrate_v7, } LATEST_VERSION = max(MIGRATIONS.keys()) diff --git a/tests/test_migrations.py b/tests/test_migrations.py index 3802aae..d208e60 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -134,6 +134,14 @@ def test_v6_migration_idempotent(self): tables = _get_table_names(self.store._conn) assert "community_summaries" in tables + def test_v7_compound_edge_indexes_exist(self): + """v7 compound edge indexes should exist after migration.""" + rows = self.store._conn.execute("PRAGMA index_list(edges)").fetchall() + indexes = {row[1] if isinstance(row, tuple) else row["name"] for row in rows} + + assert "idx_edges_target_kind" in indexes + assert "idx_edges_source_kind" in indexes + def _get_table_names(conn: sqlite3.Connection) -> set[str]: """Helper: return all table/view names in the database."""