fix(kanban): move session_id index creation from SCHEMA_SQL to migration - #28693
Closed
ticketclosed-wontfix wants to merge 1 commit into
Closed
Conversation
When the kanban schema introduced a new indexed column (session_id), the CREATE INDEX statement inside SCHEMA_SQL ran before the migration code that adds the column. On existing databases without the column, SQLite validated the column reference and crashed with: sqlite3.OperationalError: no such column: session_id The _migrate_add_optional_columns function already adds the column and creates the index, but it was never reached because coon_executescript(SCHEMA_SQL) failed first. Fix: remove the index creation from SCHEMA_SQL and let the migration function handle both old and new DBs. The index creation is now unconditional after the optional column add, guarded by IF NOT EXISTS for idempotency. Closes #28617
Collaborator
This was referenced May 19, 2026
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.
What
Remove the
CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id)statement fromSCHEMA_SQLinhermes_cli/kanban_db.py, and move the index creation into the existing_migrate_add_optional_columns()migration function.Why
When the kanban schema introduced the
session_idcolumn on thetaskstable, theCREATE INDEXstatement was placed insideSCHEMA_SQL(line 868). On existing databases that predate this column,conn.executescript(SCHEMA_SQL)fails before the column migration code runs:The
_migrate_add_optional_columnsfunction already contains the correct logic — it adds the column withALTER TABLEand then creates the index. However, it is unreachable becauseconn.executescript(SCHEMA_SQL)crashes first (line 1012 vs line 1013).Fixes #28617.
How & Tested
pytest tests/hermes_cli/test_kanban_db.py -v— 157 passed, 0 failed.test_session_id_index_existstest asserts the index is present on a fresh DB (since the index is now created unconditionally by the migration function).test_session_id_filters_listingsandtest_session_id_compose_with_tenant_filtertests continue to pass (column + index round-tripped through list queries).Platforms
Tested on Fedora 44 (x86_64), SQLite 3.49.2. The change is SQLite-only, no platform-specific code.
Checklist