📝 Commit Details:
This commit is contained in:
60
backend/utils/update_printer_locations.py
Normal file
60
backend/utils/update_printer_locations.py
Normal file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3.11
|
||||
"""
|
||||
Skript zur Aktualisierung der Drucker-Standorte in der Datenbank.
|
||||
Ändert alle Standorte von "Labor" zu "Werk 040 - Berlin - TBA".
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append('.')
|
||||
|
||||
from database.db_manager import DatabaseManager
|
||||
from models import Printer
|
||||
from datetime import datetime
|
||||
|
||||
def update_printer_locations():
|
||||
"""Aktualisiert alle Drucker-Standorte zu 'Werk 040 - Berlin - TBA'."""
|
||||
|
||||
print("=== Drucker-Standorte aktualisieren ===")
|
||||
|
||||
try:
|
||||
db = DatabaseManager()
|
||||
session = db.get_session()
|
||||
|
||||
# Alle Drucker abrufen
|
||||
all_printers = session.query(Printer).all()
|
||||
print(f"Gefundene Drucker: {len(all_printers)}")
|
||||
|
||||
if not all_printers:
|
||||
print("Keine Drucker in der Datenbank gefunden.")
|
||||
session.close()
|
||||
return
|
||||
|
||||
# Neue Standort-Bezeichnung
|
||||
new_location = "Werk 040 - Berlin - TBA"
|
||||
updated_count = 0
|
||||
|
||||
# Alle Drucker durchgehen und Standort aktualisieren
|
||||
for printer in all_printers:
|
||||
old_location = printer.location
|
||||
printer.location = new_location
|
||||
|
||||
print(f"✅ {printer.name}: '{old_location}' → '{new_location}'")
|
||||
updated_count += 1
|
||||
|
||||
# Änderungen speichern
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
print(f"\n✅ {updated_count} Drucker-Standorte erfolgreich aktualisiert")
|
||||
print(f"Neuer Standort: {new_location}")
|
||||
print("Standort-Aktualisierung abgeschlossen!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler bei der Standort-Aktualisierung: {e}")
|
||||
if 'session' in locals():
|
||||
session.rollback()
|
||||
session.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_printer_locations()
|
Reference in New Issue
Block a user