# Generated by Django 3.1.6 on 2021-02-21 13:19

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django_scopes import scopes_disabled


def set_default_owner(apps, schema_editor):
    Space = apps.get_model('cookbook', 'Space')
    User = apps.get_model('auth', 'user')

    with scopes_disabled():
        for x in Space.objects.all():
            x.created_by = User.objects.filter(is_superuser=True).first()
            x.save()


class Migration(migrations.Migration):
    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('cookbook', '0110_auto_20210221_1406'),
    ]

    operations = [
        migrations.AddField(
            model_name='space',
            name='created_by',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
        ),
        migrations.RunPython(set_default_owner),
    ]
