Run Migrations! Made Tags unique based on the combination of their db_key, db_category AND their db_tagtype fields.

This commit is contained in:
Griatch 2014-06-30 20:14:58 +02:00
parent ea059e9874
commit cda13989f6
3 changed files with 87 additions and 35 deletions

View file

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Removing unique constraint on 'Tag', fields ['db_key', 'db_category']
db.delete_unique(u'typeclasses_tag', ['db_key', 'db_category'])
# Adding unique constraint on 'Tag', fields ['db_key', 'db_category', 'db_tagtype']
db.create_unique(u'typeclasses_tag', ['db_key', 'db_category', 'db_tagtype'])
# Removing index on 'Tag', fields ['db_key', 'db_category']
db.delete_index(u'typeclasses_tag', ['db_key', 'db_category'])
# Adding index on 'Tag', fields ['db_key', 'db_category', 'db_tagtype']
db.create_index(u'typeclasses_tag', ['db_key', 'db_category', 'db_tagtype'])
def backwards(self, orm):
# Removing index on 'Tag', fields ['db_key', 'db_category', 'db_tagtype']
db.delete_index(u'typeclasses_tag', ['db_key', 'db_category', 'db_tagtype'])
# Adding index on 'Tag', fields ['db_key', 'db_category']
db.create_index(u'typeclasses_tag', ['db_key', 'db_category'])
# Removing unique constraint on 'Tag', fields ['db_key', 'db_category', 'db_tagtype']
db.delete_unique(u'typeclasses_tag', ['db_key', 'db_category', 'db_tagtype'])
# Adding unique constraint on 'Tag', fields ['db_key', 'db_category']
db.create_unique(u'typeclasses_tag', ['db_key', 'db_category'])
models = {
u'typeclasses.attribute': {
'Meta': {'object_name': 'Attribute'},
'db_attrtype': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '16', 'null': 'True', 'blank': 'True'}),
'db_category': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '128', 'null': 'True', 'blank': 'True'}),
'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_model': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '32', 'null': 'True', 'blank': 'True'}),
'db_strvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'db_value': ('src.utils.picklefield.PickledObjectField', [], {'null': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
u'typeclasses.tag': {
'Meta': {'unique_together': "(('db_key', 'db_category', 'db_tagtype'),)", 'object_name': 'Tag', 'index_together': "(('db_key', 'db_category', 'db_tagtype'),)"},
'db_category': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'db_index': 'True'}),
'db_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'db_index': 'True'}),
'db_model': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'db_index': 'True'}),
'db_tagtype': ('django.db.models.fields.CharField', [], {'max_length': '16', 'null': 'True', 'db_index': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
}
}
complete_apps = ['typeclasses']

View file

@ -539,8 +539,8 @@ class Tag(models.Model):
class Meta:
"Define Django meta options"
verbose_name = "Tag"
unique_together = (('db_key', 'db_category'),)
index_together = (('db_key', 'db_category'),)
unique_together = (('db_key', 'db_category', 'db_tagtype'),)
index_together = (('db_key', 'db_category', 'db_tagtype'),)
def __unicode__(self):
return u"%s" % self.db_key

View file

@ -116,28 +116,32 @@ def create_object(typeclass=None, key=None, location=None,
elif isinstance(typeclass, _Object) or utils.inherits_from(typeclass, _Object):
# this is already an object typeclass, extract its path
typeclass = typeclass.path
typeclass = utils.to_unicode(typeclass)
# Setup input for the create command
# handle eventual #dbref input
location = handle_dbref(location, _ObjectDB)
home = handle_dbref(home, _ObjectDB)
destination = handle_dbref(destination, _ObjectDB)
report_to = handle_dbref(report_to, _ObjectDB)
home = handle_dbref(home, _ObjectDB)
if not home:
try:
home = handle_dbref(settings.DEFAULT_HOME, _ObjectDB) if not nohome else None
except _ObjectDB.DoesNotExist:
raise _ObjectDB.DoesNotExist("settings.DEFAULT_HOME (= '%s') does not exist, or the setting is malformed." %
settings.DEFAULT_HOME)
# create new database object
new_db_object = _ObjectDB()
# assign the typeclass
typeclass = utils.to_unicode(typeclass)
new_db_object.typeclass_path = typeclass
# create new database object all in one go
new_db_object = _ObjectDB(db_key=key, db_location=location,
db_destination=destination, db_home=home,
db_typeclass_path=typeclass)
# the name/key is often set later in the typeclass. This
# is set here as a failsafe.
if key:
new_db_object.key = key
else:
if not key:
new_db_object.key = "#%i" % new_db_object.dbid
# this will either load the typeclass or the default one
# this will either load the typeclass or the default one (will also save object)
new_object = new_db_object.typeclass
if not _GA(new_object, "is_typeclass")(typeclass, exact=True):
@ -154,15 +158,15 @@ def create_object(typeclass=None, key=None, location=None,
# from now on we can use the typeclass object
# as if it was the database object.
new_object.destination = destination
# call the hook method. This is where all at_creation
# call the hook methods. This is where all at_creation
# customization happens as the typeclass stores custom
# things on its database object.
# note - this will override eventual custom keys, locations etc!
new_object.basetype_setup() # setup the basics of Exits, Characters etc.
new_object.at_object_creation()
# custom-given perms/locks overwrite hooks
# custom-given perms/locks do overwrite hooks
if permissions:
new_object.permissions.add(permissions)
if locks:
@ -170,28 +174,14 @@ def create_object(typeclass=None, key=None, location=None,
if aliases:
new_object.aliases.add(aliases)
if home:
new_object.home = home
else:
# we shouldn't need to handle dbref here (home handler should fix it), but some have
# reported issues here (issue 446).
try:
new_object.home = handle_dbref(settings.DEFAULT_HOME, _ObjectDB) if not nohome else None
except _ObjectDB.DoesNotExist:
raise _ObjectDB.DoesNotExist("settings.DEFAULT_HOME (= '%s') does not exist, or the setting is malformed." %
settings.DEFAULT_HOME)
# perform a move_to in order to display eventual messages.
# trigger relevant move_to hooks in order to display eventual messages.
if location:
new_object.move_to(location, quiet=True)
else:
# rooms would have location=None.
new_object.location = None
new_object.at_object_receive(new_object, None)
new_object.at_after_move(new_object)
# post-hook setup (mainly used by Exits)
new_object.basetype_posthook_setup()
new_object.save()
return new_object
#alias for create_object