From d1ede9ee8ddf9c63dd98c81dc4b532731819cfc0 Mon Sep 17 00:00:00 2001 From: Michilis Date: Mon, 8 Dec 2025 23:57:08 +0000 Subject: [PATCH] Fix: Add database migration for new_jackpot_delay_minutes column Existing databases were missing the new column, causing SQLITE_ERROR when updating group settings. Added migration logic to add missing columns. --- telegram_bot/src/services/database.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/telegram_bot/src/services/database.ts b/telegram_bot/src/services/database.ts index c9b2c75..f75ff62 100644 --- a/telegram_bot/src/services/database.ts +++ b/telegram_bot/src/services/database.ts @@ -120,9 +120,30 @@ class BotDatabase { CREATE INDEX IF NOT EXISTS idx_cycle_participants_telegram_id ON cycle_participants(telegram_id); `); + // Run migrations for existing databases + this.runMigrations(); + logger.debug('Database tables created/verified'); } + /** + * Run migrations for existing databases + */ + private runMigrations(): void { + if (!this.db) return; + + // Check if new_jackpot_delay_minutes column exists in groups table + const groupColumns = this.db.prepare(`PRAGMA table_info(groups)`).all() as any[]; + const hasNewJackpotDelay = groupColumns.some(col => col.name === 'new_jackpot_delay_minutes'); + + if (!hasNewJackpotDelay) { + logger.info('Running migration: adding new_jackpot_delay_minutes column to groups'); + this.db.exec(`ALTER TABLE groups ADD COLUMN new_jackpot_delay_minutes INTEGER DEFAULT 5`); + } + + logger.debug('Database migrations completed'); + } + // ═══════════════════════════════════════════════════════════════════════════ // USER METHODS // ═══════════════════════════════════════════════════════════════════════════