Coverage for product_risk_suite/threat_model/migrations/0005_threatmodelconnectionname_product.py: 73%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-07 12:45 +0000

1# Generated by Django 6.0.5 on 2026-05-19 21:32 

2 

3import django.db.models.deletion 

4from django.db import migrations, models 

5 

6def fix_invalid_products(apps, schema_editor): 

7 ThreatModel = apps.get_model('threat_model', 'ThreatModel') 

8 

9 for threat_model in ThreatModel.objects.all(): 

10 for connection_name in threat_model.connection_names.all(): 

11 connection_name.product = threat_model.product 

12 connection_name.save() 

13 

14class Migration(migrations.Migration): 

15 

16 dependencies = [ 

17 ('product', '0006_productriskentry_svg_id'), 

18 ('threat_model', '0004_threatmodelconnectionname_primary_key'), 

19 ] 

20 

21 operations = [ 

22 migrations.AddField( 

23 model_name='threatmodelconnectionname', 

24 name='product', 

25 field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='product.product'), 

26 preserve_default=False, 

27 ), 

28 migrations.RunPython(fix_invalid_products), 

29 migrations.RenameField( 

30 model_name='threatmodelconnectionname', 

31 old_name='name', 

32 new_name='tech_name', 

33 ), 

34 ]