Fix database migration for alsa_hardware_volume column

PROBLEM: App crashed on startup with existing databases:
'table audio_settings has no column named alsa_hardware_volume'

CAUSE: ALTER TABLE with 'NOT NULL' constraint fails on SQLite migrations.

FIX:
- Removed NOT NULL from ALTER TABLE statement
- Handle NULL values with unwrap_or(0) in get_settings()
- Defaults to false (disabled) for old databases

Now works with both new and existing databases.
This commit is contained in:
vicrodh committed 2026-01-19 03:52:01 -06:00
1 parent 7177f248c9
commit 31798432cb
1 file changed
+2 -2
+2 -2
View File
@@ -67,7 +67,7 @@ impl AudioSettingsStore {
// Migration: Add new columns if they don't exist (for existing databases)
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN backend_type TEXT", []);
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN alsa_plugin TEXT", []);
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN alsa_hardware_volume INTEGER NOT NULL DEFAULT 0", []);
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN alsa_hardware_volume INTEGER DEFAULT 0", []);
Ok(Self { conn })
}
@@ -95,7 +95,7 @@ impl AudioSettingsStore {
preferred_sample_rate: row.get(3)?,
backend_type,
alsa_plugin,
alsa_hardware_volume: row.get::<_, i64>(6)? != 0,
alsa_hardware_volume: row.get::<_, Option<i64>>(6)?.unwrap_or(0) != 0,
})
},
)