# Generated by Django 5.2.10 on 2026-03-01 14:50

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("events", "0002_add_null_to_correlation_fields"),
    ]

    operations = [
        migrations.CreateModel(
            name="FailedEventModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("event_id", models.CharField(db_index=True, help_text="事件 ID", max_length=64)),
                (
                    "event_type",
                    models.CharField(db_index=True, help_text="事件类型", max_length=64),
                ),
                ("payload", models.JSONField(help_text="事件负载")),
                ("metadata", models.JSONField(default=dict, help_text="事件元数据")),
                (
                    "handler_id",
                    models.CharField(db_index=True, help_text="处理器 ID", max_length=128),
                ),
                ("error_message", models.TextField(help_text="错误信息")),
                ("error_traceback", models.TextField(blank=True, help_text="错误堆栈")),
                ("retry_count", models.IntegerField(default=0, help_text="重试次数")),
                ("max_retries", models.IntegerField(default=3, help_text="最大重试次数")),
                (
                    "next_retry_at",
                    models.DateTimeField(
                        blank=True, db_index=True, help_text="下次重试时间", null=True
                    ),
                ),
                (
                    "last_retry_at",
                    models.DateTimeField(blank=True, help_text="最后重试时间", null=True),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("PENDING", "待重试"),
                            ("RETRYING", "重试中"),
                            ("SUCCESS", "已成功"),
                            ("EXHAUSTED", "已耗尽重试次数"),
                        ],
                        db_index=True,
                        default="PENDING",
                        help_text="状态",
                        max_length=16,
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
            ],
            options={
                "verbose_name": "失败事件",
                "verbose_name_plural": "失败事件",
                "db_table": "failed_event",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["status", "next_retry_at"], name="evt_fail_status_retry_idx"
                    ),
                    models.Index(fields=["handler_id", "status"], name="evt_fail_handler_idx"),
                ],
            },
        ),
    ]
