Commit 8eda5c1e authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Christos Stavrakakis
Browse files

astakos: Replace decimal field with bigint

Any values that happen to be greater than the new max (2**63-1)
are reduced to this value.
parent 44087f00
This diff is collapsed.
......@@ -64,7 +64,6 @@ from astakos.im import auth_providers as auth
import astakos.im.messages as astakos_messages
from synnefo.lib.ordereddict import OrderedDict
from snf_django.lib.db.fields import intDecimalField
from synnefo.util.text import uenc, udec
from synnefo.util import units
from astakos.im import presentation
......@@ -233,7 +232,7 @@ class Resource(models.Model):
service_type = models.CharField(_('Type'), max_length=255)
service_origin = models.CharField(max_length=255, db_index=True)
unit = models.CharField(_('Unit'), null=True, max_length=255)
uplimit = intDecimalField(default=0)
uplimit = models.BigIntegerField(default=0)
allow_in_projects = models.BooleanField(default=True)
def __str__(self):
......@@ -1021,7 +1020,7 @@ class AstakosUserAuthProvider(models.Model):
class AstakosUserQuota(models.Model):
capacity = intDecimalField()
capacity = models.BigIntegerField()
resource = models.ForeignKey(Resource)
user = models.ForeignKey(AstakosUser)
......@@ -1493,8 +1492,8 @@ class ProjectResourceGrant(models.Model):
resource = models.ForeignKey(Resource)
project_application = models.ForeignKey(ProjectApplication,
null=True)
project_capacity = intDecimalField(null=True)
member_capacity = intDecimalField(default=0)
project_capacity = models.BigIntegerField(null=True)
member_capacity = models.BigIntegerField(default=0)
objects = ProjectResourceGrantManager()
......
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
MAX = 2**63 - 1
class Migration(DataMigration):
def forwards(self, orm):
orm.Provision.objects.filter(quantity__gt=MAX).update(quantity=MAX)
orm.Holding.objects.filter(usage_min__gt=MAX).update(usage_min=MAX)
orm.Holding.objects.filter(usage_max__gt=MAX).update(usage_max=MAX)
orm.Holding.objects.filter(limit__gt=MAX).update(limit=MAX)
orm.ProvisionLog.objects.filter(delta_quantity__gt=MAX).\
update(delta_quantity=MAX)
orm.ProvisionLog.objects.filter(usage_min__gt=MAX).\
update(usage_min=MAX)
orm.ProvisionLog.objects.filter(usage_max__gt=MAX).\
update(usage_max=MAX)
orm.ProvisionLog.objects.filter(limit__gt=MAX).update(limit=MAX)
def backwards(self, orm):
"Write your backwards methods here."
models = {
'quotaholder_app.commission': {
'Meta': {'object_name': 'Commission'},
'clientkey': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'issue_datetime': ('django.db.models.fields.DateTimeField', [], {}),
'name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '4096'}),
'serial': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'quotaholder_app.holding': {
'Meta': {'unique_together': "(('holder', 'source', 'resource'),)", 'object_name': 'Holding'},
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}),
'usage_max': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'}),
'usage_min': ('snf_django.lib.db.fields.IntDecimalField', [], {'default': '0', 'max_digits': '38', 'decimal_places': '0'})
},
'quotaholder_app.provision': {
'Meta': {'object_name': 'Provision'},
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'provisions'", 'to': "orm['quotaholder_app.Commission']"}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'})
},
'quotaholder_app.provisionlog': {
'Meta': {'object_name': 'ProvisionLog'},
'delta_quantity': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}),
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'issue_time': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'limit': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}),
'log_time': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'reason': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'serial': ('django.db.models.fields.BigIntegerField', [], {}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}),
'usage_max': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'}),
'usage_min': ('snf_django.lib.db.fields.IntDecimalField', [], {'max_digits': '38', 'decimal_places': '0'})
}
}
complete_apps = ['quotaholder_app']
symmetrical = True
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Provision.quantity'
db.alter_column('quotaholder_app_provision', 'quantity', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'Holding.usage_min'
db.alter_column('quotaholder_app_holding', 'usage_min', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'Holding.usage_max'
db.alter_column('quotaholder_app_holding', 'usage_max', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'Holding.limit'
db.alter_column('quotaholder_app_holding', 'limit', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'ProvisionLog.usage_max'
db.alter_column('quotaholder_app_provisionlog', 'usage_max', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'ProvisionLog.delta_quantity'
db.alter_column('quotaholder_app_provisionlog', 'delta_quantity', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'ProvisionLog.limit'
db.alter_column('quotaholder_app_provisionlog', 'limit', self.gf('django.db.models.fields.BigIntegerField')())
# Changing field 'ProvisionLog.usage_min'
db.alter_column('quotaholder_app_provisionlog', 'usage_min', self.gf('django.db.models.fields.BigIntegerField')())
def backwards(self, orm):
# Changing field 'Provision.quantity'
db.alter_column('quotaholder_app_provision', 'quantity', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'Holding.usage_min'
db.alter_column('quotaholder_app_holding', 'usage_min', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'Holding.usage_max'
db.alter_column('quotaholder_app_holding', 'usage_max', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'Holding.limit'
db.alter_column('quotaholder_app_holding', 'limit', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'ProvisionLog.usage_max'
db.alter_column('quotaholder_app_provisionlog', 'usage_max', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'ProvisionLog.delta_quantity'
db.alter_column('quotaholder_app_provisionlog', 'delta_quantity', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'ProvisionLog.limit'
db.alter_column('quotaholder_app_provisionlog', 'limit', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
# Changing field 'ProvisionLog.usage_min'
db.alter_column('quotaholder_app_provisionlog', 'usage_min', self.gf('snf_django.lib.db.fields.IntDecimalField')(max_digits=38, decimal_places=0))
models = {
'quotaholder_app.commission': {
'Meta': {'object_name': 'Commission'},
'clientkey': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'issue_datetime': ('django.db.models.fields.DateTimeField', [], {}),
'name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '4096'}),
'serial': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'quotaholder_app.holding': {
'Meta': {'unique_together': "(('holder', 'source', 'resource'),)", 'object_name': 'Holding'},
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'limit': ('django.db.models.fields.BigIntegerField', [], {}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}),
'usage_max': ('django.db.models.fields.BigIntegerField', [], {'default': '0'}),
'usage_min': ('django.db.models.fields.BigIntegerField', [], {'default': '0'})
},
'quotaholder_app.provision': {
'Meta': {'object_name': 'Provision'},
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'quantity': ('django.db.models.fields.BigIntegerField', [], {}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'serial': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'provisions'", 'to': "orm['quotaholder_app.Commission']"}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'})
},
'quotaholder_app.provisionlog': {
'Meta': {'object_name': 'ProvisionLog'},
'delta_quantity': ('django.db.models.fields.BigIntegerField', [], {}),
'holder': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'issue_time': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'limit': ('django.db.models.fields.BigIntegerField', [], {}),
'log_time': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'reason': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'resource': ('django.db.models.fields.CharField', [], {'max_length': '4096'}),
'serial': ('django.db.models.fields.BigIntegerField', [], {}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '4096', 'null': 'True'}),
'usage_max': ('django.db.models.fields.BigIntegerField', [], {}),
'usage_min': ('django.db.models.fields.BigIntegerField', [], {})
}
}
complete_apps = ['quotaholder_app']
\ No newline at end of file
......@@ -31,8 +31,6 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from snf_django.lib.db.fields import intDecimalField
from django.db.models import (Model, BigIntegerField, CharField, DateTimeField,
ForeignKey, AutoField)
......@@ -43,9 +41,9 @@ class Holding(Model):
source = CharField(max_length=4096, null=True)
resource = CharField(max_length=4096, null=False)
limit = intDecimalField()
usage_min = intDecimalField(default=0)
usage_max = intDecimalField(default=0)
limit = BigIntegerField()
usage_min = BigIntegerField(default=0)
usage_max = BigIntegerField(default=0)
class Meta:
unique_together = (('holder', 'source', 'resource'),)
......@@ -68,7 +66,7 @@ class Provision(Model):
source = CharField(max_length=4096, null=True)
resource = CharField(max_length=4096, null=False)
quantity = intDecimalField()
quantity = BigIntegerField()
def todict(self):
return {'holder': self.holder,
......@@ -90,8 +88,8 @@ class ProvisionLog(Model):
holder = CharField(max_length=4096)
source = CharField(max_length=4096, null=True)
resource = CharField(max_length=4096)
limit = intDecimalField()
usage_min = intDecimalField()
usage_max = intDecimalField()
delta_quantity = intDecimalField()
limit = BigIntegerField()
usage_min = BigIntegerField()
usage_max = BigIntegerField()
delta_quantity = BigIntegerField()
reason = CharField(max_length=4096)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment