feat: add poll start/end endpoints, poll.leading WS handler, and poll state persistence

Adds POST /:id/voting/start and POST /:id/voting/end endpoints that
broadcast poll lifecycle events and persist poll state to the sessions
table. The poll.leading WebSocket message is now handled server-side
(rebroadcast + DB persist) with self-healing for polls started before
the persistence columns existed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cottongin
2026-05-07 20:43:39 -04:00
parent 1c9f0ef280
commit 9cd601bab2
4 changed files with 158 additions and 0 deletions

View File

@@ -63,6 +63,33 @@ function initializeDatabase() {
// Column already exists, ignore error
}
// Poll state columns on sessions
try {
db.exec(`ALTER TABLE sessions ADD COLUMN poll_active INTEGER DEFAULT 0`);
} catch (err) {
// Column already exists, ignore error
}
try {
db.exec(`ALTER TABLE sessions ADD COLUMN poll_started_at TEXT`);
} catch (err) {
// Column already exists, ignore error
}
try {
db.exec(`ALTER TABLE sessions ADD COLUMN poll_leading_game_id INTEGER`);
} catch (err) {
// Column already exists, ignore error
}
try {
db.exec(`ALTER TABLE sessions ADD COLUMN poll_leading_label TEXT`);
} catch (err) {
// Column already exists, ignore error
}
try {
db.exec(`ALTER TABLE sessions ADD COLUMN poll_leading_votes INTEGER`);
} catch (err) {
// Column already exists, ignore error
}
// Session games table
db.exec(`
CREATE TABLE IF NOT EXISTS session_games (