Initial commit - copied workspace after database cleanup
This commit is contained in:
54
server/sync_existing_clients.py
Normal file
54
server/sync_existing_clients.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Einmaliges Skript zur Synchronisation aller bestehenden Client-Gruppenzuordnungen
|
||||
Verwendung: python sync_existing_clients.py
|
||||
"""
|
||||
from server.mqtt_helper import publish_multiple_client_groups
|
||||
from models.models import Client
|
||||
from server.database import Session
|
||||
import sys
|
||||
import os
|
||||
sys.path.append('/workspace')
|
||||
|
||||
|
||||
def main():
|
||||
print("Synchronisiere bestehende Client-Gruppenzuordnungen mit MQTT...")
|
||||
|
||||
session = Session()
|
||||
try:
|
||||
# Alle aktiven Clients abrufen
|
||||
clients = session.query(Client).filter(Client.is_active == True).all()
|
||||
|
||||
if not clients:
|
||||
print("Keine aktiven Clients gefunden.")
|
||||
return
|
||||
|
||||
print(f"Gefunden: {len(clients)} aktive Clients")
|
||||
|
||||
# Mapping erstellen
|
||||
client_group_mappings = {
|
||||
client.uuid: client.group_id for client in clients}
|
||||
|
||||
# Alle auf einmal publizieren
|
||||
success_count, failed_count = publish_multiple_client_groups(
|
||||
client_group_mappings)
|
||||
|
||||
print(f"Synchronisation abgeschlossen:")
|
||||
print(f" Erfolgreich: {success_count}")
|
||||
print(f" Fehlgeschlagen: {failed_count}")
|
||||
print(f" Gesamt: {len(clients)}")
|
||||
|
||||
if failed_count == 0:
|
||||
print("✅ Alle Clients erfolgreich synchronisiert!")
|
||||
else:
|
||||
print(
|
||||
f"⚠️ {failed_count} Clients konnten nicht synchronisiert werden.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler: {e}")
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user