# Generated by Django 3.2.16 on 2022-11-19 18:19

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

def update_invitation_table(apps, schema_editor):
    User = apps.get_model("users", "User")
    Invitation = apps.get_model("users", "Invitation")
    for user in User.objects.all():
        if user.invitation:
            Invitation.objects.filter(id=user.invitation.id).update(invited_user_id=user.id)


def rewind(*args, **kwargs):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0021_auto_20210703_1810'),
    ]

    operations = [
        migrations.AddField(
            model_name='invitation',
            name='invited_user',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user_invitations', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AlterField(
            model_name='invitation',
            name='owner',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invitations', to=settings.AUTH_USER_MODEL),
        ),
        migrations.RunPython(update_invitation_table, rewind),
    ]
