Passed
Push — master ( 4f3982...e0f0d3 )
by Alexander
02:17
created

tcms.testcases.migrations.0009_populate_missing_text_history   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A forward_copy_data() 0 14 4
1
from django.db import migrations
2
3
4
def forward_copy_data(apps, schema_editor):
5
    TestCase = apps.get_model('testcases', 'TestCase')
6
7
    for test_case in TestCase.objects.all():
8
        history = test_case.history.latest()
9
10
        # In 0006_merge_text_field_into_testcase_model we may have
11
        # failed to save the text into the history record leaving
12
        # historical records with text == None.
13
        # If the TC was not modified since then we try to fix the last
14
        # historical record
15
        if test_case.text and not history.text:
16
            history.text = test_case.text
17
            history.save()
18
19
20
class Migration(migrations.Migration):
21
22
    dependencies = [
23
        ('testcases', '0008_notifications_default_true'),
24
    ]
25
26
    operations = [
27
        # copy the data from the related model
28
        migrations.RunPython(forward_copy_data),
29
    ]
30