Skip to content

Commit

Permalink
custom migration
Browse files Browse the repository at this point in the history
for existing assessments, fix score
  • Loading branch information
eric-intuitem committed Apr 28, 2024
1 parent f81232d commit 8ca4609
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
# Generated by Django 5.0.4 on 2024-04-28 15:34
# well-known scores added manually

from django.db import migrations, models


WELL_KNOWN_SCORES = {
"urn:intuitem:risk:framework:tisax-v6.0.2": (0, 5),
"urn:intuitem:risk:framework:cis-controls-v8": (0, 5),
"urn:intuitem:risk:framework:ccm-controls-v4": (0, 5),
"urn:intuitem:risk:framework:ccb-cff-2023-03-01": (1, 5),
}

def fix_well_known_scores(apps, schema_editor):
Framework = apps.get_model('core', 'Framework')
ComplianceAssessment = apps.get_model('core', 'ComplianceAssessment')
for framework in Framework.objects.all():
if framework.urn in WELL_KNOWN_SCORES:
(framework.min_score, framework.max_score) = WELL_KNOWN_SCORES[framework.urn]
framework.save()
for assessment in ComplianceAssessment.objects.all():
if assessment.framework.urn in WELL_KNOWN_SCORES:
(assessment.min_score, assessment.max_score) = WELL_KNOWN_SCORES[assessment.framework.urn]
assessment.save()

class Migration(migrations.Migration):
dependencies = [
("core", "0009_framework_max_score_framework_min_score_and_more"),
Expand Down Expand Up @@ -66,4 +86,5 @@ class Migration(migrations.Migration):
migrations.DeleteModel(
name="RequirementLevel",
),
migrations.RunPython(fix_well_known_scores),
]

0 comments on commit 8ca4609

Please sign in to comment.