# Generated by Django 5.1.7 on 2025-03-16 13:58

import secrets
import users.models
from django.db import migrations
from django.db.models import CharField, Q


def fill_missing_tokens(apps, _):
    User = apps.get_model("users", "User")
    for user in User.objects.filter(
        Q(token__isnull=True) | Q(token__exact="")
    ).iterator():
        user.token = secrets.token_urlsafe(24)
        user.save(update_fields=["token"])



class Migration(migrations.Migration):

    dependencies = [
        ("users", "0031_remove_user_last_search_type_valid_and_more"),
    ]

    operations = [
        migrations.RunPython(fill_missing_tokens),
        migrations.AlterField(
            model_name="user",
            name="token",
            field=CharField(
                default=users.models.generate_token,
                help_text="Token for external webhooks",
                max_length=32,
                unique=True,
            ),
        ),
    ]
