Passed
Push — master ( bd2622...f167a9 )
by Paolo
06:51
created

validation.migrations.0003_auto_20200225_1651   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 31
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A reverse_func() 0 17 3
A forwards_func() 0 21 3
1
# Generated by Django 2.2.10 on 2020-02-25 15:51
2
3
import ast
4
5
from django.db import migrations
6
7
8
def forwards_func(apps, schema_editor):
9
    # We get the model from the versioned app registry;
10
    # if we directly import it, it'll be the wrong version
11
12
    ValidationSummary = apps.get_model(
13
        "validation",
14
        "ValidationSummary")
15
16
    db_alias = schema_editor.connection.alias
17
18
    # Update validation summary
19
    for summary in ValidationSummary.objects.using(db_alias):
20
        new_messages = []
21
22
        for message in summary.old_messages:
23
            data = ast.literal_eval(message)
24
            new_messages.append(data)
25
26
        # now update new_messages column
27
        summary.new_messages = new_messages
28
        summary.save()
29
30
31
def reverse_func(apps, schema_editor):
32
    ValidationSummary = apps.get_model(
33
        "validation",
34
        "ValidationSummary")
35
36
    db_alias = schema_editor.connection.alias
37
38
    # Update validation summary
39
    for summary in ValidationSummary.objects.using(db_alias):
40
        old_messages = []
41
42
        for message in summary.new_messages:
43
            old_messages.append(message)
44
45
        # now update old_messages column
46
        summary.old_messages = old_messages
47
        summary.save()
48
49
50
class Migration(migrations.Migration):
51
52
    dependencies = [
53
        ('validation', '0002_auto_20200225_1651'),
54
    ]
55
56
    operations = [
57
        migrations.RunPython(forwards_func, reverse_func),
58
    ]
59