Total Complexity | 4 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |