From 58b6f41b7ba67ce9720e069eab8d2f78af113eb3 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 13 Jul 2017 20:59:32 +0200 Subject: [PATCH] Add migration to finally remove the last playerdb_ tables --- .../0010_delete_old_player_tables.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 evennia/typeclasses/migrations/0010_delete_old_player_tables.py diff --git a/evennia/typeclasses/migrations/0010_delete_old_player_tables.py b/evennia/typeclasses/migrations/0010_delete_old_player_tables.py new file mode 100644 index 0000000000..72dc691f7c --- /dev/null +++ b/evennia/typeclasses/migrations/0010_delete_old_player_tables.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-13 18:47 +from __future__ import unicode_literals + +from django.db import migrations, OperationalError, connection + + +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 + + +def _drop_table(db_cursor, table_name): + if _table_exists(db_cursor, table_name): + sql_drop = "DROP TABLE %s;" % table_name + db_cursor.execute(sql_drop) + + +def drop_tables(apps, schema_migrator): + db_cursor = connection.cursor() + _drop_table(db_cursor, "players_playerdb") + _drop_table(db_cursor, "players_playerdb_db_attributes") + _drop_table(db_cursor, "players_playerdb_db_tags") + _drop_table(db_cursor, "players_playerdb_groups") + _drop_table(db_cursor, "players_playerdb_user_permissions") + + +class Migration(migrations.Migration): + + dependencies = [ + ('typeclasses', '0009_rename_player_cmdsets_typeclasses'), + ] + + operations = [ + migrations.RunPython(drop_tables) + ]