Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code-review-graph-vscode/src/backend/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`;
}
Expand Down
2 changes: 2 additions & 0 deletions code_review_graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
"""

Expand Down
14 changes: 14 additions & 0 deletions code_review_graph/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand All @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down