mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 00:36:30 +01:00
Run Migrations. Migrated to new Attribute schema, converting old attributes. Not fully tested yet.
This commit is contained in:
parent
a1d818f8aa
commit
2a7c45d6e8
18 changed files with 825 additions and 55 deletions
38
src/typeclasses/migrations/0001_initial.py
Normal file
38
src/typeclasses/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# -*- 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):
|
||||
# Adding model 'Attribute'
|
||||
db.create_table(u'typeclasses_attribute', (
|
||||
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('db_key', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)),
|
||||
('db_value', self.gf('src.utils.picklefield.PickledObjectField')(null=True)),
|
||||
('db_lock_storage', self.gf('django.db.models.fields.TextField')(blank=True)),
|
||||
('db_date_created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
|
||||
))
|
||||
db.send_create_signal(u'typeclasses', ['Attribute'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting model 'Attribute'
|
||||
db.delete_table(u'typeclasses_attribute')
|
||||
|
||||
|
||||
models = {
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['typeclasses']
|
||||
79
src/typeclasses/migrations/0002_resave_attrs.py
Normal file
79
src/typeclasses/migrations/0002_resave_attrs.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(DataMigration):
|
||||
depends_on = (('server', '0003_add_tmpattr'),)
|
||||
no_dry_run=True
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
|
||||
|
||||
for tmpattr in orm['server.TmpAttribute'].objects.all():
|
||||
typ = tmpattr.db_obj_type
|
||||
dbid = tmpattr.db_obj_id
|
||||
if typ == 'objectdb':
|
||||
try:
|
||||
dbobj = orm['objects.ObjectDB'].objects.get(dbid)
|
||||
except:
|
||||
print "could not find objid %i" % objid
|
||||
continue
|
||||
elif typ == 'playerdb':
|
||||
try:
|
||||
dbobj = orm['players.PlayerDB'].objects.get(dbid)
|
||||
except:
|
||||
print "could not find objid %i" % objid
|
||||
continue
|
||||
elif typ == 'scriptdb':
|
||||
try:
|
||||
dbobj = orm['scripts.ScriptDB'].objects.get(dbid)
|
||||
except:
|
||||
print "could not find objid %i" % objid
|
||||
continue
|
||||
else:
|
||||
print "Wrong object type to store on: %s" % typ
|
||||
continue
|
||||
dbattr = orm['typeclasses.Attribute'].create(db_key=tmpattr.db_key,
|
||||
db_value=tmpattr.db_value,
|
||||
db_lock_storage=tmpattr.db_lock_storage,
|
||||
db_date_created=tmpattr.db_date)
|
||||
|
||||
dbattr.save()
|
||||
dbobj.db_attributes.add(dbattr)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
raise RuntimeError("Cannot revert this migration.")
|
||||
|
||||
models = {
|
||||
u'server.serverconfig': {
|
||||
'Meta': {'object_name': 'ServerConfig'},
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'}),
|
||||
'db_value': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
'server.tmpattribute': {
|
||||
'Meta': {'object_name': 'TmpAttribute'},
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_obj_id': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
|
||||
'db_obj_type': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
u'typeclasses.attribute': {
|
||||
'Meta': {'object_name': 'Attribute'},
|
||||
'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'db_lock_storage': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['server', 'typeclasses']
|
||||
symmetrical = True
|
||||
0
src/typeclasses/migrations/__init__.py
Normal file
0
src/typeclasses/migrations/__init__.py
Normal file
|
|
@ -71,7 +71,6 @@ _DA = object.__delattr__
|
|||
#
|
||||
#------------------------------------------------------------
|
||||
|
||||
|
||||
class Attribute(SharedMemoryModel):
|
||||
"""
|
||||
Abstract django model.
|
||||
|
|
@ -88,34 +87,22 @@ class Attribute(SharedMemoryModel):
|
|||
mode - which type of data is stored in attribute
|
||||
lock_storage - perm strings
|
||||
obj - which object the attribute is defined on
|
||||
date_created - when the attribute was created
|
||||
value - the data stored in the attribute
|
||||
what is actually stored in the field is a dict
|
||||
date_created - when the attribute was created.
|
||||
value - the data stored in the attribute, in pickled form
|
||||
using wrappers to be able to store/retrieve models.
|
||||
|
||||
{type : nodb|dbobj|dbiter,
|
||||
data : <data>}
|
||||
|
||||
where type is info for the loader, telling it if holds a single
|
||||
dbobject (dbobj), have to do a full scan for dbrefs (dbiter) or
|
||||
if it is a normal Python structure without any dbobjs inside it
|
||||
and can thus return it without further action (nodb).
|
||||
"""
|
||||
|
||||
#
|
||||
# Attribute Database Model setup
|
||||
#
|
||||
#
|
||||
# These database fields are all set using their corresponding properties,
|
||||
# named same as the field, but withtout the db_* prefix.
|
||||
|
||||
db_key = models.CharField('key', max_length=255, db_index=True)
|
||||
# access through the value property
|
||||
db_value = PickledObjectField('value', null=True)
|
||||
# Lock storage
|
||||
db_lock_storage = models.TextField('locks', blank=True)
|
||||
# references the object the attribute is linked to (this is set
|
||||
# by each child class to this abstract class)
|
||||
db_obj = None # models.ForeignKey("RefencedObject") #TODO-remove
|
||||
# time stamp
|
||||
db_date_created = models.DateTimeField('date_created', editable=False, auto_now_add=True)
|
||||
|
||||
|
|
@ -132,9 +119,9 @@ class Attribute(SharedMemoryModel):
|
|||
|
||||
class Meta:
|
||||
"Define Django meta options"
|
||||
#abstract = True
|
||||
verbose_name = "Evennia Attribute"
|
||||
|
||||
|
||||
# Wrapper properties to easily set database fields. These are
|
||||
# @property decorators that allows to access these fields using
|
||||
# normal python operations (without having to remember to save()
|
||||
|
|
@ -1003,7 +990,7 @@ class TypedObject(SharedMemoryModel):
|
|||
"""
|
||||
attr_obj = get_attr_cache(self, attribute_name)
|
||||
if not attr_obj:
|
||||
attr_obj = _GA(self, "db_atttributes").filter(db_key__iexact=attribute_name)
|
||||
attr_obj = _GA(self, "db_attributes").filter(db_key__iexact=attribute_name)
|
||||
if not attr_obj:
|
||||
if raise_exception:
|
||||
raise AttributeError
|
||||
|
|
@ -1315,4 +1302,4 @@ class TypedObject(SharedMemoryModel):
|
|||
|
||||
|
||||
# connect to signal
|
||||
m2m_changed.connect(update_attr_cache, sender=TypedObject.db_attributes.through)
|
||||
#m2m_changed.connect(update_attr_cache, sender=TypedObject.db_attributes.through)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue