"""Add metadata field to `RateLimitCounter` for advanced algorithms."""

# Generated by Django 5.2.1 on 2025-10-13 06:50

from django.db import migrations, models

# Django 4.1+ exposes migrations.RenameIndex; Django 4.0 does not.
# Fetch it dynamically so older installations can still apply this migration.
RenameIndex = getattr(migrations, "RenameIndex", None)


class Migration(migrations.Migration):
    """Add storage for serialized counter state and update indexes."""

    dependencies = [
        ("django_smart_ratelimit", "0001_initial"),
    ]

    rename_operations = []
    if RenameIndex is not None:
        # On Django versions that support RenameIndex, keep index names tidy.
        rename_operations.extend(
            [
                RenameIndex(
                    model_name="ratelimitcounter",
                    new_name="django_smar_key_a333b4_idx",
                    old_name="django_smar_key_24c4a0_idx",
                ),
                RenameIndex(
                    model_name="ratelimitcounter",
                    new_name="django_smar_window__892d5c_idx",
                    old_name="django_smar_window__3e0e6a_idx",
                ),
                RenameIndex(
                    model_name="ratelimitentry",
                    new_name="django_smar_key_af838f_idx",
                    old_name="django_smar_key_8ff7e9_idx",
                ),
                RenameIndex(
                    model_name="ratelimitentry",
                    new_name="django_smar_expires_684344_idx",
                    old_name="django_smar_expires_f8e4cc_idx",
                ),
                RenameIndex(
                    model_name="ratelimitentry",
                    new_name="django_smar_key_59d90e_idx",
                    old_name="django_smar_key_b42c8a_idx",
                ),
            ]
        )

    # Always run the schema changes below; prepend rename ops when available.
    operations = rename_operations + [
        migrations.AddField(
            model_name="ratelimitcounter",
            name="data",
            field=models.TextField(
                blank=True,
                help_text="Serialized metadata/state for advanced algorithms",
                null=True,
            ),
        ),
        migrations.AlterField(
            model_name="ratelimitconfig",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
        migrations.AlterField(
            model_name="ratelimitcounter",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
        migrations.AlterField(
            model_name="ratelimitentry",
            name="id",
            field=models.BigAutoField(
                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
            ),
        ),
    ]
