<reponame>snakrani/discovery<gh_stars>0
# Generated by Django 2.0.2 on 2018-03-05 23:01

from django.db import migrations, models
import django.db.models.deletion


def migrate_membership(apps, schema_editor):
    PoolPIID = apps.get_model('vendors', 'PoolPIID')
    PoolMembership = apps.get_model('vendors', 'PoolMembership')
    PoolMembershipZone = apps.get_model('vendors', 'PoolMembershipZone')
    
    for membership in PoolPIID.objects.all():
        new_membership, created = PoolMembership.objects.get_or_create(
            vendor=membership.vendor, 
            pool=membership.pool, 
            piid=membership.piid
        )
        if membership.zone:
            PoolMembershipZone.objects.get_or_create(
                membership=new_membership,
                zone=membership.zone
            )


class Migration(migrations.Migration):

    dependencies = [
        ('categories', '0003_auto_20180301_2027'),
        ('vendors', '0029_auto_20180301_2027'),
    ]

    operations = [
        migrations.CreateModel(
            name='PoolMembership',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('piid', models.CharField(max_length=128)),
                ('pool', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='categories.Pool')),
            ],
        ),
        migrations.CreateModel(
            name='PoolMembershipZone',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('membership', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='zone', to='vendors.PoolMembership')),
                ('zone', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='categories.Zone')),
            ],
        ),
        migrations.AlterField(
            model_name='vendor',
            name='pools',
            field=models.ManyToManyField(through='vendors.PoolMembership', to='categories.Pool'),
        ),
        migrations.AddField(
            model_name='poolmembership',
            name='vendor',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vendors.Vendor'),
        ),
        
        migrations.RunPython(migrate_membership),
        
        migrations.RemoveField(
            model_name='poolpiid',
            name='pool',
        ),
        migrations.RemoveField(
            model_name='poolpiid',
            name='vendor',
        ),
        migrations.RemoveField(
            model_name='poolpiid',
            name='zone',
        ),
        
        migrations.DeleteModel(
            name='PoolPIID',
        )
    ]

# Generated by Django 2.0.2 on 2018-03-05 23:01

from django.db import migrations, models
import django.db.models.deletion


def migrate_membership(apps, schema_editor):
    PoolPIID = apps.get_model('vendors', 'PoolPIID')
    PoolMembership = apps.get_model('vendors', 'PoolMembership')
    PoolMembershipZone = apps.get_model('vendors', 'PoolMembershipZone')
    
    for membership in PoolPIID.objects.all():
        new_membership, created = PoolMembership.objects.get_or_create(
            vendor=membership.vendor, 
            pool=membership.pool, 
            piid=membership.piid
        )
        if membership.zone:
            PoolMembershipZone.objects.get_or_create(
                membership=new_membership,
                zone=membership.zone
            )


class Migration(migrations.Migration):

    dependencies = [
        ('categories', '0003_auto_20180301_2027'),
        ('vendors', '0029_auto_20180301_2027'),
    ]

    operations = [
        migrations.CreateModel(
            name='PoolMembership',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('piid', models.CharField(max_length=128)),
                ('pool', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='categories.Pool')),
            ],
        ),
        migrations.CreateModel(
            name='PoolMembershipZone',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('membership', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='zone', to='vendors.PoolMembership')),
                ('zone', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='categories.Zone')),
            ],
        ),
        migrations.AlterField(
            model_name='vendor',
            name='pools',
            field=models.ManyToManyField(through='vendors.PoolMembership', to='categories.Pool'),
        ),
        migrations.AddField(
            model_name='poolmembership',
            name='vendor',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vendors.Vendor'),
        ),
        
        migrations.RunPython(migrate_membership),
        
        migrations.RemoveField(
            model_name='poolpiid',
            name='pool',
        ),
        migrations.RemoveField(
            model_name='poolpiid',
            name='vendor',
        ),
        migrations.RemoveField(
            model_name='poolpiid',
            name='zone',
        ),
        
        migrations.DeleteModel(
            name='PoolPIID',
        )
    ]
# Generated by Django 2.0.2 on 2018-03-05 23:01