Skip to content
Closed
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
12 changes: 12 additions & 0 deletions hermes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,18 @@ def _init_schema(self):
"CREATE UNIQUE INDEX IF NOT EXISTS idx_sessions_title_unique "
"ON sessions(title) WHERE title IS NOT NULL"
)
except sqlite3.IntegrityError:
# Duplicate titles exist — deduplicate by keeping the newest row
cursor.execute(
"DELETE FROM sessions WHERE rowid NOT IN ("
" SELECT MAX(rowid) FROM sessions"
" WHERE title IS NOT NULL GROUP BY title"
")"
)
cursor.execute(
"CREATE UNIQUE INDEX IF NOT EXISTS idx_sessions_title_unique "
"ON sessions(title) WHERE title IS NOT NULL"
)
except sqlite3.OperationalError:
pass # Index already exists

Expand Down
Loading