diff --git a/src/authentic2/migrations/0030_clean_admin_tools_tables.py b/src/authentic2/migrations/0030_clean_admin_tools_tables.py new file mode 100644 index 000000000..1b3bec335 --- /dev/null +++ b/src/authentic2/migrations/0030_clean_admin_tools_tables.py @@ -0,0 +1,30 @@ +from django.db import migrations +import logging + + +def noop(apps, schema_editor): + pass + + +def clean_admin_tools_tables(apps, schema_editor): + try: + with schema_editor.connection.cursor() as cursor: + cursor.execute("SELECT table_name FROM information_schema.tables " + "WHERE table_schema = current_schema() " + "AND table_name LIKE 'admin_tools%'") + rows = cursor.fetchall() + for table_name, in rows: + cursor.execute('DROP TABLE "%s" CASCADE' % table_name) + except Exception: + logging.getLogger(__name__).exception('migration authentic2.0030 failed') + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentic2', '0029_auto_20201013_1614'), + ] + + operations = [ + migrations.RunPython(clean_admin_tools_tables, noop), + ]