Browse Source

properly detect if an upgrade is necessary using Django's DB introspection.

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
8c09edeee7
  1. 35
      pyweb/mumble/management/__init__.py

35
pyweb/mumble/management/__init__.py

@ -14,7 +14,7 @@
* GNU General Public License for more details.
"""
from django.db import connection, transaction
from django.db import connection
from django.db.models import signals
from mumble import models
@ -22,31 +22,24 @@ from mumble import models
from update_schema import update_schema
from server_detect import find_existing_instances
cursor = connection.cursor()
if not transaction.is_managed():
managed_before = False
transaction.enter_transaction_management(True)
transaction.managed(True)
else:
managed_before = True
tablename = models.Mumble._meta.db_table
cursor = connection.cursor()
try:
cursor.execute( "SELECT server_id FROM mumble_mumble;" )
uptodate = False
if tablename in connection.introspection.get_table_list(cursor):
fields = connection.introspection.get_table_description(cursor, tablename)
for entry in fields:
if entry[0] == "server_id":
uptodate = True
break
else:
# Table doesn't yet exist, so syncdb will create it properly
uptodate = True
except cursor.db.connection.Error:
# server_id field does not exist -> DB needs to be updated.
transaction.rollback()
if not uptodate:
signals.post_syncdb.connect( update_schema, sender=models );
else:
transaction.rollback()
signals.post_syncdb.connect( find_existing_instances, sender=models );
finally:
if not managed_before:
transaction.managed(False)
transaction.leave_transaction_management()
Loading…
Cancel
Save