# Generated by Django 3.2 on 2021-06-07 15:20

from django.db import migrations


def add_dataset(apps, schema_editor):
    project_model = apps.get_model('core', 'Project')
    for project in project_model.objects.all():
        groomed = project.groomed_segmentations.first()
        if groomed is None:
            project.delete()
            continue

        project.dataset = groomed.segmentation.subject.dataset
        project.save()


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0003_project_dataset'),
    ]

    operations = [
        migrations.RunPython(add_dataset, reverse_code=migrations.RunPython.noop),
    ]
