Fixed a migration bug when starting with a clean database.

This commit is contained in:
Griatch 2011-04-21 20:44:45 +00:00
parent 6f0d21802b
commit 7dc4901ccc

View file

@ -2,9 +2,10 @@
import datetime import datetime
from south.db import db from south.db import db
from south.v2 import DataMigration from south.v2 import DataMigration
from django.db import models from django.db import models, utils
import pickle import pickle
class Migration(DataMigration): class Migration(DataMigration):
def forwards(self, orm): def forwards(self, orm):
@ -13,16 +14,20 @@ class Migration(DataMigration):
# we are fixing a situation were the serverconfig value last_initial_setup_step was left at 1 instead of -1 # we are fixing a situation were the serverconfig value last_initial_setup_step was left at 1 instead of -1
# as it should (due to a bug in the setter). This causes db errors as the initial_setup thinks it needs to # as it should (due to a bug in the setter). This causes db errors as the initial_setup thinks it needs to
# run again. # run again.
if orm['objects.ObjectDB'].objects.filter(id=1) and orm["objects.ObjectDB"].objects.filter(id=2): try:
# only an issue the critical objects have already been created if orm['objects.ObjectDB'].objects.filter(id=1) and orm["objects.ObjectDB"].objects.filter(id=2):
conf = orm.ServerConfig.objects.filter(db_key="last_initial_setup_step") # only an issue the critical objects have already been created
if conf: conf = orm.ServerConfig.objects.filter(db_key="last_initial_setup_step")
conf = conf[0] if conf:
if pickle.loads(str(conf.db_value)) == 1: conf = conf[0]
# this shouldn't be 1 if objects already exists. This is the bug. Fix the error. if pickle.loads(str(conf.db_value)) == 1:
conf.db_value = pickle.dumps(-1) # this shouldn't be 1 if objects already exists. This is the bug. Fix the error.
conf.save() conf.db_value = pickle.dumps(-1)
conf.save()
except utils.DatabaseError:
# this will happen if we start the db from scratch (in which case this migration fix is not needed)
pass
def backwards(self, orm): def backwards(self, orm):