diff --git a/component_catalog/migrations/0011_to_delete_temp_fake_values.py b/component_catalog/migrations/0011_to_delete_temp_fake_values.py new file mode 100644 index 0000000..5840dac --- /dev/null +++ b/component_catalog/migrations/0011_to_delete_temp_fake_values.py @@ -0,0 +1,35 @@ +# Generated by Django 5.0.9 on 2024-11-08 13:26 + +from django.db import migrations +from django.db.models import Count + + +def generate_random_risk_score(): + import random + from decimal import Decimal + + return Decimal(f"{random.uniform(0, 10):.2f}") + + +def set_random_risk_score(apps, schema_editor): + Package = apps.get_model("component_catalog", "Package") + + qs = Package.objects.annotate( + vulnerability_count=Count("affected_by_vulnerabilities", distinct=True) + ).filter(vulnerability_count__gt=0) + + for package in qs: + risk_score = generate_random_risk_score() + Package.objects.filter(pk=package.pk).update(risk_score=risk_score) + + +class Migration(migrations.Migration): + + dependencies = [ + ('component_catalog', '0010_component_risk_score_package_risk_score'), + ] + + operations = [ + migrations.RunPython(set_random_risk_score), + ] +