Add a sanity check for comm migration

This commit is contained in:
Griatch 2017-07-09 11:12:20 +02:00
parent f45bd4921d
commit c1326eaf23

View file

@ -2,7 +2,17 @@
# Generated by Django 1.11.2 on 2017-07-05 17:26
from __future__ import unicode_literals
from django.db import migrations, models
from django.db import migrations, models, connection
from django.db import OperationalError
def _table_exists(db_cursor, tablename):
"Returns bool if table exists or not"
sql_check_exists = "SELECT * from %s;" % tablename
try:
db_cursor.execute(sql_check_exists)
return True
except OperationalError:
return False
class Migration(migrations.Migration):
@ -12,6 +22,13 @@ class Migration(migrations.Migration):
('comms', '0012_merge_20170617_2017'),
]
db_cursor = connection.cursor()
if not _table_exists(db_cursor, 'comms_msg_db_hide_from_players'):
# OBS - this is run BEFORE migrations are run!
# not a migration of an existing database
operations = []
else:
operations = [
migrations.AddField(
model_name='channeldb',