# Generated by Django 4.2.9 on 2024-11-28 17:49

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid

from funkwhale_api.federation import utils
from django.urls import reverse

def gen_uuid(apps, schema_editor):
    MyModel = apps.get_model("playlists", "Playlist")
    for row in MyModel.objects.all():
        unique_uuid = uuid.uuid4()
        while MyModel.objects.filter(uuid=unique_uuid).exists():
            unique_uuid = uuid.uuid4()

        fid = utils.full_url(
            reverse("federation:music:playlist-detail", kwargs={"uuid": unique_uuid})
        )
        row.uuid = unique_uuid
        row.fid = fid
        row.save(update_fields=["uuid", "fid"])

class Migration(migrations.Migration):

    dependencies = [
        ("federation", "0028_auto_20221027_1141"),
        ("playlists", "0005_remove_playlist_user_playlist_actor"),
    ]

    operations = [
        migrations.AddField(
            model_name="playlisttrack",
            name="uuid",
            field=models.UUIDField(default=uuid.uuid4, null=True),
        ),
        migrations.AddField(
            model_name="playlisttrack",
            name="fid",
            field=models.URLField(max_length=500
            ),
        ),
        migrations.AddField(
            model_name="playlisttrack",
            name="url",
            field=models.URLField(blank=True, max_length=500, null=True),
        ),
        migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop),
                migrations.AlterField(
            model_name="playlist",
            name="uuid",
            field=models.UUIDField(default=uuid.uuid4, null=False, unique=True),
        ),
        migrations.AlterField(
            model_name="playlisttrack",
            name="fid",
            field=models.URLField(
                db_index=True, max_length=500, unique=True
            ),),
    ]
