diff --git a/evennia/settings_default.py b/evennia/settings_default.py index d12c21ba98..528fcafac4 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -250,6 +250,17 @@ DATABASES = { # If you get errors about the database having gone away after long idle # periods, shorten this value (e.g. MySQL defaults to a timeout of 8 hrs) CONN_MAX_AGE = 3600 * 7 +# When removing or renaming models, such models stored in Attributes may +# become orphaned and will return as None. If the change is a rename (that +# is, there is a 1:1 pk mapping between the old and the new), the unserializer +# can convert old to new when retrieving them. This is a list of tuples +# (old_natural_key, new_natural_key). Note that Django ContentTypes' +# natural_keys are themselves tuples (appname, modelname). If new_natural_key +# does not exist, `None` will be returned and stored back as if no replacement +# was set. +ATTRIBUTE_STORED_MODEL_RENAME = [ + ((u"players", u"playerdb"), (u"accounts", u"accountdb")), + ((u"typeclasses", u"defaultplayer"), (u"typeclasses", u"defaultaccount"))] ###################################################################### diff --git a/evennia/utils/dbserialize.py b/evennia/utils/dbserialize.py index 0ff0678be2..0877636a3c 100644 --- a/evennia/utils/dbserialize.py +++ b/evennia/utils/dbserialize.py @@ -115,13 +115,18 @@ def _init_globals(): _FROM_MODEL_MAP = defaultdict(str) _FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all())) if not _TO_MODEL_MAP: + from django.conf import settings _TO_MODEL_MAP = defaultdict(str) _TO_MODEL_MAP.update(dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all())) + for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME: + _TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None) # handle old player models by converting them to accounts _TO_MODEL_MAP[(u"players", u"playerdb")] = _TO_MODEL_MAP[(u"accounts", u"accountdb")] + _TO_MODEL_MAP[(u"typeclasses", u"defaultplayer")] = _TO_MODEL_MAP[(u"typeclasses", u"defaultaccount")] if not _SESSION_HANDLER: from evennia.server.sessionhandler import SESSION_HANDLER as _SESSION_HANDLER + # # SaverList, SaverDict, SaverSet - Attribute-specific helper classes and functions #