fix(gateway): move handoff_state index to DEFERRED_INDEX_SQL

The index references the handoff_state column which is added by
_reconcile_columns() on legacy databases. Placing it in SCHEMA_SQL
causes 'no such column' errors during schema migration tests because
SCHEMA_SQL runs before reconciliation.

Move to DEFERRED_INDEX_SQL which runs after _reconcile_columns() —
matching the existing pattern used by idx_messages_session_active.

Refs: #43504, #40695
(cherry picked from commit 40ecd61d49)
This commit is contained in:
kenyonxu 2026-06-11 13:06:19 +08:00 committed by kshitij
parent 0695a6bcec
commit a23aa4320e

View file

@ -740,6 +740,8 @@ CREATE INDEX IF NOT EXISTS idx_sessions_session_key
ON sessions(session_key, started_at DESC);
CREATE INDEX IF NOT EXISTS idx_sessions_gateway_peer
ON sessions(source, user_id, chat_id, chat_type, thread_id, started_at DESC);
CREATE INDEX IF NOT EXISTS idx_sessions_handoff_state
ON sessions(handoff_state, started_at);
"""
FTS_SQL = """