From 9f6f16fb7d18a216f10f53eeeb8a11b09fbf9d48 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 30 Sep 2017 15:53:34 +0200 Subject: [PATCH] Update migration with mysql/postgreql exception --- .../0010_delete_old_player_tables.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/evennia/typeclasses/migrations/0010_delete_old_player_tables.py b/evennia/typeclasses/migrations/0010_delete_old_player_tables.py index b3881b68ae..07fd808000 100644 --- a/evennia/typeclasses/migrations/0010_delete_old_player_tables.py +++ b/evennia/typeclasses/migrations/0010_delete_old_player_tables.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals from django.db import migrations, connection +_ENGINE = None def _table_exists(db_cursor, tablename): "Returns bool if table exists or not" @@ -11,8 +12,26 @@ def _table_exists(db_cursor, tablename): def _drop_table(db_cursor, table_name): + global _ENGINE + if not _ENGINE: + from django.conf import settings + try: + _ENGINE = settings.DATABASES["default"]["ENGINE"] + except KeyError: + _ENGINE = settings.DATABASE_ENGINE + if _table_exists(db_cursor, table_name): - sql_drop = "DROP TABLE %s;" % table_name + if _ENGINE == "django.db.backends.mysql": + sql_drop = "SET FOREIGN_KEY_CHECKS=0;"\ + "DROP TABLE {table};"\ + "SET FOREIGN_KEY_CHECKS=1;".format(table=table_name) + elif _ENGINE == "postgresql_psycopg2": + sql_drop = "ALTER TABLE {table} DISABLE TRIGGER ALL;"\ + "DROP TABLE {table};"\ + "ALTER TABLE {table} ENABLE TRIGGER ALL;".format(table=table_name) + else: # sqlite3, other databases + sql_drop = "DROP TABLE {table};".format(table=table_name) + db_cursor.execute(sql_drop)