DB-Migration: fehlende autostart_* Spalten hinzufügen und Defaults setzen

This commit is contained in:
2025-08-22 08:53:18 +02:00
parent bdeabaad2e
commit ce2eea5f43

View File

@@ -39,6 +39,21 @@ func InitDB() (*DB, error) {
return nil, err
}
// Migration: fehlende Spalten hinzufügen (für bestehende DBs)
// autostart_cron
_, err = db.Exec("ALTER TABLE pcs ADD COLUMN autostart_cron TEXT DEFAULT '30 7 * * Mon-Fri'")
if err != nil {
// Spalte existiert bereits, ignorieren
}
// autostart_enabled
_, err = db.Exec("ALTER TABLE pcs ADD COLUMN autostart_enabled BOOLEAN DEFAULT 0")
if err != nil {
// Spalte existiert bereits, ignorieren
}
// Standardwerte für evtl. NULL-Einträge setzen
_, _ = db.Exec("UPDATE pcs SET autostart_cron = '30 7 * * Mon-Fri' WHERE autostart_cron IS NULL")
_, _ = db.Exec("UPDATE pcs SET autostart_enabled = 0 WHERE autostart_enabled IS NULL")
// Log-Tabelle erstellen
createLogTableSQL := `
CREATE TABLE IF NOT EXISTS wol_logs (