Added optional support for database migrations with south. The game/migrate.py program is a simple wrapper that runs the suitable commands for setting up a database and updating it, respectively.

This commit is contained in:
Griatch 2010-10-31 18:21:23 +00:00
parent 7eaf3d221c
commit 7fb6362dc4
9 changed files with 153 additions and 30 deletions

View file

@ -129,7 +129,7 @@ class ObjectDB(TypedObject):
# comma-separated list of alias-names of this object. Note that default
# searches only search aliases in the same location as caller.
db_aliases = models.ForeignKey(Alias, db_index=True, blank=True, null=True)
db_aliases = models.ForeignKey(Alias, blank=True, null=True, db_index=True)
# If this is a character object, the player is connected here.
db_player = models.ForeignKey("players.PlayerDB", blank=True, null=True)
# The location in the game world. Since this one is likely

View file

@ -48,7 +48,7 @@ class ScriptHandler(object):
interval = "inf"
next_repeat = "inf"
repeats = "inf"
if script.interval:
if script.interval > 0:
interval = script.interval
if script.repeats:
repeats = script.repeats

View file

@ -441,8 +441,8 @@ try:
except ImportError:
pass
# South handles automatic database scheme migrations when evennia updates
#try:
# import south
# INSTALLED_APPS = INSTALLED_APPS + ('south',)
#except ImportError:
# pass
try:
import south
INSTALLED_APPS = INSTALLED_APPS + ('south',)
except ImportError:
pass

View file

@ -4,17 +4,17 @@ from django.db.models.base import Model, ModelBase
from manager import SharedMemoryManager
TCACHE = {}
TCACHE = {} # test cache, for debugging /Griatch
class SharedMemoryModelBase(ModelBase):
def __new__(cls, name, bases, attrs):
super_new = super(ModelBase, cls).__new__
parents = [b for b in bases if isinstance(b, SharedMemoryModelBase)]
if not parents:
# If this isn't a subclass of Model, don't do anything special.
return super_new(cls, name, bases, attrs)
return super(SharedMemoryModelBase, cls).__new__(cls, name, bases, attrs)
#def __new__(cls, name, bases, attrs):
# super_new = super(ModelBase, cls).__new__
# parents = [b for b in bases if isinstance(b, SharedMemoryModelBase)]
# if not parents:
# # If this isn't a subclass of Model, don't do anything special.
# print "not a subclass of Model", name, bases
# return super_new(cls, name, bases, attrs)
# return super(SharedMemoryModelBase, cls).__new__(cls, name, bases, attrs)
def __call__(cls, *args, **kwargs):
"""
@ -49,6 +49,9 @@ class SharedMemoryModel(Model):
# subclass now?
__metaclass__ = SharedMemoryModelBase
class Meta:
abstract = True
def _get_cache_key(cls, args, kwargs):
"""
This method is used by the caching subsystem to infer the PK value from the constructor arguments.

View file

@ -21,22 +21,21 @@ def reload_modules():
"""
Reload modules that don't have any variables that can be reset.
Note that python reloading is a tricky art and strange things have
been known to happen if debugging and reloading a lot while
working with src/ modules. A cold reboot is often needed
eventually.
been known to happen if debugging and reloading a lot. A server
cold reboot is often needed eventually.
"""
# We protect e.g. src/ from reload since reloading it in a running
# server can create unexpected results (and besides, we should
# never need to do that anyway. Updating src requires a server
# reboot).
# server can create unexpected results (and besides, non-evennia devs
# should never need to do that anyway). Updating src requires a server
# reboot.
protected_dirs = ('src.',)
# flag 'dangerous' typeclasses (those which retain a memory
# reference, notably Scripts with a timer component) for
# non-reload, since these cannot be safely cleaned from memory
# without causing havoc. A server reboot is required for updating
# these.
# these (or killing all running, timed scripts).
unsafe_modules = []
for scriptobj in ScriptDB.objects.get_all_scripts():
if (scriptobj.interval > -1) and scriptobj.typeclass_path: