from django.db import migrations, models, transaction


def init_groups_and_permissions(app, schema_editor):
    from aircox import permissions

    Program = app.get_model("aircox", "Program")

    with transaction.atomic():
        for program in Program.objects.all():
            permissions.program.init(program)


class Migration(migrations.Migration):
    atomic = False
    dependencies = [
        ("aircox", "0021_alter_schedule_timezone"),
    ]

    operations = [
        migrations.RunPython(init_groups_and_permissions),
        migrations.AlterField(
            model_name="program",
            name="editors_group",
            field=models.ForeignKey(
                on_delete=models.deletion.CASCADE,
                to="auth.group",
                verbose_name="editors",
            ),
        ),
    ]
