Fixed the migrations from a pre-populated database to the many-char-per-player branch.
This commit is contained in:
parent
ea4c30a0b1
commit
4669b8ed89
3 changed files with 37 additions and 6 deletions
|
|
@ -1,24 +1,43 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import datetime, pickle
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
from src.typeclasses.models import PackedDBobject
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
"Write your forwards methods here."
|
||||
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
|
||||
|
||||
lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)"
|
||||
lockstring2 = "attrread:false();attredit:false();attrcreate:false()"
|
||||
if not db.dry_run:
|
||||
for player in orm['players.PlayerDB'].objects.all():
|
||||
attr = orm['players.PlayerAttribute']()
|
||||
attr.db_obj = player
|
||||
attr.save()
|
||||
char = player.db_obj
|
||||
attr.db_obj.value = [char] or []
|
||||
if char:
|
||||
val = pickle.dumps(("iter", [PackedDBobject(char.id, "objectdb", char.db_key)]))
|
||||
else:
|
||||
val = pickle.dumps(("iter", []))
|
||||
orm['players.PlayerAttribute'].objects.create(db_key="_playable_characters",
|
||||
db_obj=player,
|
||||
db_lock_storage=lockstring,
|
||||
db_value=val)
|
||||
suser = char and char.id == 1
|
||||
if suser:
|
||||
# move the superuser unmask attribute for the superuser (note that this
|
||||
# is not a security risk, it only works if player's superuser bit is set too)
|
||||
val = pickle.dumps(("simple", suser))
|
||||
orm['objects.ObjAttribute'].objects.create(db_key="_superuser_character",
|
||||
db_obj=char,
|
||||
db_lock_storage=lockstring2,
|
||||
db_value=val)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
raise RuntimeError("This migration cannot be reverted.")
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
|
|
@ -66,6 +85,15 @@ class Migration(DataMigration):
|
|||
'db_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
'objects.objattribute': {
|
||||
'Meta': {'object_name': 'ObjAttribute'},
|
||||
'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.CharField', [], {'max_length': '512', 'blank': 'True'}),
|
||||
'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['objects.ObjectDB']"}),
|
||||
'db_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
|
||||
},
|
||||
'objects.objectdb': {
|
||||
'Meta': {'object_name': 'ObjectDB'},
|
||||
'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ def create_objects():
|
|||
god_character.locks.add("examine:perm(Immortals);edit:false();delete:false();boot:false();msg:all();puppet:false()")
|
||||
|
||||
god_character.save()
|
||||
# note that there is no security issue with setting the _superuser_character flag - the system
|
||||
# will only grant superuser access to a character with this flag if its Player also has the
|
||||
# superuser bit set. It only marks that the character should not "mask" the superuser privileges.
|
||||
god_character.set_attribute("_superuser_character", True)
|
||||
god_player.set_attribute("_first_login", True)
|
||||
god_player.set_attribute("_last_puppet", god_character)
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ class Attribute(SharedMemoryModel):
|
|||
The Attribute class defines the following properties:
|
||||
key - primary identifier
|
||||
mode - which type of data is stored in attribute
|
||||
permissions - perm strings
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue