diff --git a/core/db.py b/core/db.py index d808011..d35c90a 100644 --- a/core/db.py +++ b/core/db.py @@ -719,6 +719,23 @@ def _migrate(conn: sqlite3.Connection): ) conn.commit() + # Create indexes for project_links (KIN-INFRA-008). + # Guard: indexes must be created AFTER the table exists. + if "project_links" in existing_tables: + existing_indexes = {r[0] for r in conn.execute( + "SELECT name FROM sqlite_master WHERE type='index'" + ).fetchall()} + if "idx_project_links_to" not in existing_indexes: + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_project_links_to ON project_links(to_project)" + ) + conn.commit() + if "idx_project_links_from" not in existing_indexes: + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_project_links_from ON project_links(from_project)" + ) + conn.commit() + def _seed_default_hooks(conn: sqlite3.Connection): """Seed default hooks for the kin project (idempotent).