|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Generated by Django 1.11.21 on 2019-07-01 11:23 |
|
3
|
|
|
from __future__ import unicode_literals |
|
4
|
|
|
|
|
5
|
|
|
from django.db import migrations |
|
6
|
|
|
|
|
7
|
|
|
from common.constants import SAMPLE_STORAGE, SAMPLE_STORAGE_PROCESSING |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
def convert_storage(apps, schema_editor): |
|
11
|
|
|
"""read from storage field and set data to storage_new""" |
|
12
|
|
|
|
|
13
|
|
|
# When using multiple databases, you may need to figure out whether or |
|
14
|
|
|
# not to run a migration against a particular database. For example, |
|
15
|
|
|
# you may want to only run a migration on a particular database. |
|
16
|
|
|
# whithout the following condition, I will fail tests during migrations, |
|
17
|
|
|
# while default database works as expected |
|
18
|
|
|
if schema_editor.connection.alias != 'default': |
|
19
|
|
|
return |
|
20
|
|
|
|
|
21
|
|
|
Sample = apps.get_model('image_app', 'Sample') |
|
22
|
|
|
|
|
23
|
|
|
for sample in Sample.objects.all(): |
|
24
|
|
|
if sample.storage is None: |
|
25
|
|
|
continue |
|
26
|
|
|
|
|
27
|
|
|
sample.storage_new = SAMPLE_STORAGE.get_value_by_desc(sample.storage) |
|
28
|
|
|
sample.save() |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def convert_storage_processing(apps, schema_editor): |
|
32
|
|
|
""" |
|
33
|
|
|
read from storage_processing field and set data to storage_processing_new |
|
34
|
|
|
""" |
|
35
|
|
|
|
|
36
|
|
|
if schema_editor.connection.alias != 'default': |
|
37
|
|
|
return |
|
38
|
|
|
|
|
39
|
|
|
Sample = apps.get_model('image_app', 'Sample') |
|
40
|
|
|
|
|
41
|
|
|
for sample in Sample.objects.all(): |
|
42
|
|
|
if sample.storage_processing is None: |
|
43
|
|
|
continue |
|
44
|
|
|
|
|
45
|
|
|
sample.storage_processing_new = \ |
|
46
|
|
|
SAMPLE_STORAGE_PROCESSING.get_value_by_desc( |
|
47
|
|
|
sample.storage_processing) |
|
48
|
|
|
sample.save() |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
class Migration(migrations.Migration): |
|
52
|
|
|
|
|
53
|
|
|
dependencies = [ |
|
54
|
|
|
('image_app', '0023_auto_20190701_1317'), |
|
55
|
|
|
] |
|
56
|
|
|
|
|
57
|
|
|
operations = [ |
|
58
|
|
|
migrations.RunPython(convert_storage), |
|
59
|
|
|
migrations.RunPython(convert_storage_processing), |
|
60
|
|
|
] |
|
61
|
|
|
|