# Generated by Django 2.2.15 on 2020-08-14 11:23

from django.db import migrations

TABLES = [
    'surveys_articletagrule',
    'surveys_combinationrule',
    'surveys_groupmembershiprule',
    'surveys_molosurveyformfield',
    'surveys_molosurveypage',
    'surveys_molosurveypage_translated_pages',
    'surveys_molosurveypageview',
    'surveys_molosurveysubmission',
    'surveys_personalisablesurvey',
    'surveys_personalisablesurveyformfield',
    'surveys_segmentusergroup',
    'surveys_segmentusergroup_users',
    'surveys_surveyresponserule',
    'surveys_surveysindexpage',
    'surveys_surveysubmissiondatarule',
    'surveys_surveytermsconditions',
    'surveys_termsandconditionsindexpage',
    'surveys_termsandconditionsindexpage_translated_pages',

    'yourwords_termsandconditions',
    'yourwords_thankyou',
    'yourwords_yourwordscompetition',
    'yourwords_yourwordscompetition_translated_pages',
    'yourwords_yourwordscompetitionentry',
    'yourwords_yourwordscompetitionindexpage',

    'polls_choice',
    'polls_choice_choice_votes',
    'polls_choice_translated_pages',
    'polls_choicevote',
    'polls_choicevote_choice',
    'polls_freetextquestion',
    'polls_freetextvote',
    'polls_pollsindexpage',
    'polls_question',
    'polls_question_translated_pages',
]


def remove_tables(apps, schema_editor):
    sql = "DROP TABLE IF EXISTS {} CASCADE;"

    if schema_editor.connection.vendor == 'sqlite':
        sql = "DROP TABLE IF EXISTS {};"

    for table in TABLES:
        schema_editor.execute(sql.format(table))


class Migration(migrations.Migration):

    dependencies = [
        ('gem', '0043_invite_site'),
    ]

    operations = [
        migrations.RunPython(remove_tables)
    ]
