-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate random value for the risk_score #98
Signed-off-by: tdruez <[email protected]>
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
component_catalog/migrations/0011_to_delete_temp_fake_values.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
] | ||
|