root / snf-astakos-app / astakos / quotaholder_app / migrations / 0003_data.py @ b32a2c5d
History | View | Annotate | Download (11 kB)
1 |
# encoding: utf-8
|
---|---|
2 |
import datetime |
3 |
from south.db import db |
4 |
from south.v2 import DataMigration |
5 |
from django.db import models |
6 |
from django.db.models import F |
7 |
|
8 |
class Migration(DataMigration): |
9 |
|
10 |
def forwards(self, orm): |
11 |
# Delete service holdings
|
12 |
orm.Holding.objects.filter( |
13 |
entity__in=['cyclades', 'pithos+']).delete() |
14 |
|
15 |
# Populate new fields
|
16 |
holdings = orm.Holding.objects.all().select_related() |
17 |
holdings.update(source="system")
|
18 |
holdings.update(usage_min=F('imported')-F('exporting')+ |
19 |
F('returned')-F('releasing')) |
20 |
holdings.update(usage_max=F('importing')-F('exported')+ |
21 |
F('returning')-F('released')) |
22 |
|
23 |
for holding in holdings: |
24 |
holding.holder = holding.entity.entity |
25 |
holding.limit = holding.policy.capacity |
26 |
holding.save() |
27 |
|
28 |
h_pith = orm.Holding.objects.filter(resource="pithos+.diskspace")
|
29 |
h_pith.update(resource="pithos.diskspace")
|
30 |
|
31 |
provisions = orm.Provision.objects.all().select_related() |
32 |
provisions.update(source="system")
|
33 |
|
34 |
for provision in provisions: |
35 |
provision.holder = provision.serial.entity.entity |
36 |
provision.save() |
37 |
|
38 |
p_pith = orm.Provision.objects.filter(resource="pithos+.diskspace")
|
39 |
p_pith.update(resource="pithos.diskspace")
|
40 |
|
41 |
plogs = orm.ProvisionLog.objects.all() |
42 |
plogs.update(holder=F('target'))
|
43 |
plogs.update(source="system")
|
44 |
plogs.update(limit=F('target_capacity'))
|
45 |
plogs.update(usage_min=F('target_imported')-F('target_exported')+ |
46 |
F('target_returned')-F('target_released')) |
47 |
plogs.update(usage_max=F('usage_min'))
|
48 |
|
49 |
pl_pith = orm.ProvisionLog.objects.filter(resource="pithos+.diskspace")
|
50 |
pl_pith.update(resource="pithos.diskspace")
|
51 |
|
52 |
|
53 |
def backwards(self, orm): |
54 |
"Write your backwards methods here."
|
55 |
|
56 |
|
57 |
models = { |
58 |
'quotaholder_app.callserial': {
|
59 |
'Meta': {'unique_together': "(('serial', 'clientkey'),)", 'object_name': 'CallSerial'}, |
60 |
'clientkey': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
61 |
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
62 |
'serial': ('django.db.models.fields.BigIntegerField', [], {}) |
63 |
}, |
64 |
'quotaholder_app.commission': {
|
65 |
'Meta': {'object_name': 'Commission'}, |
66 |
'clientkey': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
67 |
'entity': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['quotaholder_app.Entity']"}), |
68 |
'issue_time': ('django.db.models.fields.CharField', [], {'default': "'2013-04-29T09:17:31.6951'", 'max_length': '24'}), |
69 |
'name': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}), |
70 |
'serial': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) |
71 |
}, |
72 |
'quotaholder_app.entity': {
|
73 |
'Meta': {'object_name': 'Entity'}, |
74 |
'entity': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'primary_key': 'True'}), |
75 |
'key': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
76 |
'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'entities'", 'to': "orm['quotaholder_app.Entity']"}) |
77 |
}, |
78 |
'quotaholder_app.holder': {
|
79 |
'Meta': {'object_name': 'Holder'}, |
80 |
'attribute': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'primary_key': 'True'}), |
81 |
'intval': ('django.db.models.fields.BigIntegerField', [], {}), |
82 |
'strval': ('django.db.models.fields.CharField', [], {'max_length': '4096'}) |
83 |
}, |
84 |
'quotaholder_app.holding': {
|
85 |
'Meta': {'unique_together': "(('entity', 'resource'),)", 'object_name': 'Holding'}, |
86 |
'entity': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['quotaholder_app.Entity']"}), |
87 |
'exported': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
88 |
'exporting': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
89 |
'flags': ('django.db.models.fields.BigIntegerField', [], {'default': '0'}), |
90 |
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'db_index': 'True'}), |
91 |
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
92 |
'imported': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
93 |
'importing': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
94 |
'limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
95 |
'policy': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['quotaholder_app.Policy']"}), |
96 |
'released': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
97 |
'releasing': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
98 |
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
99 |
'returned': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
100 |
'returning': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
101 |
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}), |
102 |
'usage_max': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}), |
103 |
'usage_min': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}) |
104 |
}, |
105 |
'quotaholder_app.policy': {
|
106 |
'Meta': {'object_name': 'Policy'}, |
107 |
'capacity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
108 |
'export_limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
109 |
'import_limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
110 |
'policy': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'primary_key': 'True'}), |
111 |
'quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}) |
112 |
}, |
113 |
'quotaholder_app.provision': {
|
114 |
'Meta': {'object_name': 'Provision'}, |
115 |
'entity': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['quotaholder_app.Entity']"}), |
116 |
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'db_index': 'True'}), |
117 |
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
118 |
'quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
119 |
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
120 |
'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'provisions'", 'to': "orm['quotaholder_app.Commission']"}), |
121 |
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}) |
122 |
}, |
123 |
'quotaholder_app.provisionlog': {
|
124 |
'Meta': {'object_name': 'ProvisionLog'}, |
125 |
'delta_quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
126 |
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
127 |
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
128 |
'issue_time': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
129 |
'limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
130 |
'log_time': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
131 |
'name': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
132 |
'reason': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
133 |
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
134 |
'serial': ('django.db.models.fields.BigIntegerField', [], {}), |
135 |
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
136 |
'source_capacity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
137 |
'source_export_limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
138 |
'source_exported': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
139 |
'source_import_limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
140 |
'source_imported': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
141 |
'source_quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
142 |
'source_released': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
143 |
'source_returned': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
144 |
'target': ('django.db.models.fields.CharField', [], {'max_length': '4096'}), |
145 |
'target_capacity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
146 |
'target_export_limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
147 |
'target_exported': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
148 |
'target_import_limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
149 |
'target_imported': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
150 |
'target_quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
151 |
'target_released': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
152 |
'target_returned': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
153 |
'usage_max': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}), |
154 |
'usage_min': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}) |
155 |
} |
156 |
} |
157 |
|
158 |
complete_apps = ['quotaholder_app']
|