# Generated by Django 2.2.13 on 2020-07-14 21:42

from django.db import migrations, models

def update_policy(apps, schema_editor):
    SyncList = apps.get_model('galaxy', 'SyncList')
    db_alias = schema_editor.connection.alias

    synclists = SyncList.objects.using(db_alias).all().filter(policy__in=('whitelist', 'blacklist'))
    remap = {'whitelist': 'include',
             'blacklist': 'exclude'}

    for synclist in synclists:
        synclist.policy = remap[synclist.policy]
        synclist.save()


class Migration(migrations.Migration):

    dependencies = [
        ('galaxy', '0003_synclist_upstream_and_migrate'),
    ]

    operations = [
        migrations.AlterField(
            model_name='synclist',
            name='policy',
            field=models.CharField(choices=[('exclude', 'exclude'), ('include', 'include'),
                                            ('blacklist', 'blacklist'), ('whitelist', 'whitelist')],
                                   default='exclude', max_length=64),
        ),

        migrations.RunPython(code=update_policy),

        migrations.AlterField(
            model_name='synclist',
            name='policy',
            field=models.CharField(choices=[('exclude', 'exclude'), ('include', 'include')],
                                   default='exclude', max_length=64),
        ),

    ]
