InitDB: Dummy-PC 'Test' automatisch anlegen, falls pcs leer ist
This commit is contained in:
@@ -77,6 +77,23 @@ func InitDB() (*DB, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Falls keine PCs vorhanden sind, Dummy-PC anlegen
|
||||||
|
var pcCount int
|
||||||
|
err = db.QueryRow("SELECT COUNT(*) FROM pcs").Scan(&pcCount)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warnung: Konnte Anzahl der PCs nicht ermitteln: %v", err)
|
||||||
|
} else if pcCount == 0 {
|
||||||
|
_, insErr := db.Exec(
|
||||||
|
"INSERT INTO pcs (name, mac, ip, autostart_cron, autostart_enabled, created_at, updated_at) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
|
||||||
|
"Test", "00:11:22:33:AA:FF", "192.168.0.1", "30 7 * * Mon-Fri", 0,
|
||||||
|
)
|
||||||
|
if insErr != nil {
|
||||||
|
log.Printf("Warnung: Konnte Dummy-PC nicht anlegen: %v", insErr)
|
||||||
|
} else {
|
||||||
|
log.Println("Dummy-PC 'Test' in InitDB automatisch angelegt (leere Datenbank)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Füge IP-Spalte hinzu, falls sie nicht existiert
|
// Füge IP-Spalte hinzu, falls sie nicht existiert
|
||||||
_, err = db.Exec("ALTER TABLE pcs ADD COLUMN ip TEXT DEFAULT ''")
|
_, err = db.Exec("ALTER TABLE pcs ADD COLUMN ip TEXT DEFAULT ''")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user