#!/usr/bin/env python3 """ Database migration script om bestaande incidenten van 10-punts naar 5-punts Snauw-index te converteren """ from app import create_app, db from app.models import Incident def convert_10_to_5_scale(old_severity): """ Converteer 10-punts schaal naar 5-punts Snauw-index Mapping: 1-2 (10-punts) -> 1 (Lichte correctie) 3-4 (10-punts) -> 2 (Geprikkelde waarschuwing) 5-6 (10-punts) -> 3 (Openlijke snauw) 7-8 (10-punts) -> 4 (Bijtende aanval) 9-10 (10-punts) -> 5 (Explosieve uitval) """ if old_severity <= 2: return 1 elif old_severity <= 4: return 2 elif old_severity <= 6: return 3 elif old_severity <= 8: return 4 else: # 9-10 return 5 def migrate_incidents(): """Migreer alle incidenten naar de nieuwe 5-punts schaal""" app = create_app() with app.app_context(): # Vind alle incidenten die mogelijk nog de oude 10-punts schaal gebruiken incidents_to_update = Incident.query.filter(Incident.severity > 5).all() if not incidents_to_update: print("āœ… Geen incidenten gevonden die migratie nodig hebben.") return True print(f"šŸ”„ Migratie van {len(incidents_to_update)} incidenten naar 5-punts Snauw-index...") updated_count = 0 for incident in incidents_to_update: old_severity = incident.severity new_severity = convert_10_to_5_scale(old_severity) incident.severity = new_severity print(f" Incident {incident.id}: {old_severity} -> {new_severity}") updated_count += 1 try: db.session.commit() print(f"āœ… Migratie voltooid! {updated_count} incidenten bijgewerkt.") except Exception as e: db.session.rollback() print(f"āŒ Fout bij migratie: {e}") return False return True if __name__ == '__main__': print("šŸš€ Database migratie naar Snauw-index (5-punts schaal)") print("=" * 50) success = migrate_incidents() if success: print("\n✨ Migratie succesvol voltooid!") print("\nNieuw Snauw-index systeem:") print("1 - Lichte correctie") print("2 - Geprikkelde waarschuwing") print("3 - Openlijke snauw") print("4 - Bijtende aanval") print("5 - Explosieve uitval") else: print("\nāŒ Migratie mislukt. Controleer de database verbinding.")