snauwcounter/migrate_to_snauw_index.py
Michael Trip b56e866071
All checks were successful
Build and Push Image / build-and-push (push) Successful in 1m26s
initial commit
2026-01-09 21:58:53 +01:00

79 lines
2.4 KiB
Python

#!/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.")