|
| 1 | +from django.db import migrations, models |
| 2 | +import django.db.models.deletion |
| 3 | +from django.core.validators import MaxValueValidator, MinValueValidator |
| 4 | +from vulnerabilities.improver import MAX_CONFIDENCE |
| 5 | + |
| 6 | +def split_packagerelatedvulnerability(apps, schema_editor): |
| 7 | + PackageRelatedVulnerability = apps.get_model('vulnerabilities', 'PackageRelatedVulnerability') |
| 8 | + FixingPackageRelatedVulnerability = apps.get_model('vulnerabilities', 'FixingPackageRelatedVulnerability') |
| 9 | + AffectedByPackageRelatedVulnerability = apps.get_model('vulnerabilities', 'AffectedByPackageRelatedVulnerability') |
| 10 | + |
| 11 | + for prv in PackageRelatedVulnerability.objects.all(): |
| 12 | + if prv.fix: |
| 13 | + FixingPackageRelatedVulnerability.objects.create( |
| 14 | + package=prv.package, |
| 15 | + vulnerability=prv.vulnerability, |
| 16 | + created_by=prv.created_by, |
| 17 | + confidence=prv.confidence, |
| 18 | + ) |
| 19 | + else: |
| 20 | + AffectedByPackageRelatedVulnerability.objects.create( |
| 21 | + package=prv.package, |
| 22 | + vulnerability=prv.vulnerability, |
| 23 | + created_by=prv.created_by, |
| 24 | + confidence=prv.confidence, |
| 25 | + ) |
| 26 | + |
| 27 | +def reverse_migration(apps, schema_editor): |
| 28 | + FixingPackageRelatedVulnerability = apps.get_model('vulnerabilities', 'FixingPackageRelatedVulnerability') |
| 29 | + AffectedByPackageRelatedVulnerability = apps.get_model('vulnerabilities', 'AffectedByPackageRelatedVulnerability') |
| 30 | + PackageRelatedVulnerability = apps.get_model('vulnerabilities', 'PackageRelatedVulnerability') |
| 31 | + |
| 32 | + for fpv in FixingPackageRelatedVulnerability.objects.all(): |
| 33 | + PackageRelatedVulnerability.objects.create( |
| 34 | + package=fpv.package, |
| 35 | + vulnerability=fpv.vulnerability, |
| 36 | + created_by=fpv.created_by, |
| 37 | + confidence=fpv.confidence, |
| 38 | + fix=True, |
| 39 | + ) |
| 40 | + |
| 41 | + for apv in AffectedByPackageRelatedVulnerability.objects.all(): |
| 42 | + PackageRelatedVulnerability.objects.create( |
| 43 | + package=apv.package, |
| 44 | + vulnerability=apv.vulnerability, |
| 45 | + created_by=apv.created_by, |
| 46 | + confidence=apv.confidence, |
| 47 | + fix=False, |
| 48 | + ) |
| 49 | + |
| 50 | +class Migration(migrations.Migration): |
| 51 | + |
| 52 | + dependencies = [ |
| 53 | + ("vulnerabilities", "0070_alter_advisory_created_by_and_more"), |
| 54 | + ] |
| 55 | + |
| 56 | + operations = [ |
| 57 | + migrations.RunPython(split_packagerelatedvulnerability, reverse_migration), |
| 58 | + ] |
0 commit comments