# Generated by Django 5.2.10 on 2026-02-03 12:21

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="EventSubscriptionModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "subscription_id",
                    models.CharField(
                        db_index=True, help_text="订阅唯一标识符", max_length=64, unique=True
                    ),
                ),
                (
                    "handler_id",
                    models.CharField(db_index=True, help_text="处理器 ID", max_length=128),
                ),
                ("event_types", models.JSONField(help_text="订阅的事件类型列表")),
                ("is_active", models.BooleanField(default=True, help_text="是否激活")),
                ("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": "event_subscription",
                "ordering": ["handler_id"],
            },
        ),
        migrations.CreateModel(
            name="EventSnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "snapshot_id",
                    models.CharField(
                        db_index=True, help_text="快照唯一标识符", max_length=64, unique=True
                    ),
                ),
                (
                    "aggregate_type",
                    models.CharField(db_index=True, help_text="聚合根类型", max_length=64),
                ),
                (
                    "aggregate_id",
                    models.CharField(db_index=True, help_text="聚合根 ID", max_length=64),
                ),
                ("version", models.IntegerField(help_text="版本号")),
                ("state", models.JSONField(help_text="状态")),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
            ],
            options={
                "verbose_name": "事件快照",
                "verbose_name_plural": "事件快照",
                "db_table": "event_snapshot",
                "ordering": ["-version"],
                "indexes": [
                    models.Index(
                        fields=["aggregate_type", "aggregate_id", "-version"],
                        name="event_snaps_aggrega_e43741_idx",
                    )
                ],
                "unique_together": {("aggregate_type", "aggregate_id", "version")},
            },
        ),
        migrations.CreateModel(
            name="StoredEventModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "event_id",
                    models.CharField(
                        db_index=True, help_text="事件唯一标识符", max_length=64, unique=True
                    ),
                ),
                (
                    "event_type",
                    models.CharField(db_index=True, help_text="事件类型", max_length=64),
                ),
                ("payload", models.JSONField(help_text="事件负载")),
                ("metadata", models.JSONField(blank=True, default=dict, help_text="事件元数据")),
                (
                    "correlation_id",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="关联 ID（用于关联多个事件）",
                        max_length=64,
                    ),
                ),
                (
                    "causation_id",
                    models.CharField(
                        blank=True, help_text="因果 ID（用于追踪事件链）", max_length=64
                    ),
                ),
                ("occurred_at", models.DateTimeField(db_index=True, help_text="事件发生时间")),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="存储时间"),
                ),
                ("version", models.IntegerField(default=1, help_text="事件版本")),
            ],
            options={
                "verbose_name": "存储事件",
                "verbose_name_plural": "存储事件",
                "db_table": "stored_event",
                "ordering": ["-occurred_at", "-created_at"],
                "indexes": [
                    models.Index(
                        fields=["event_type", "-occurred_at"], name="stored_even_event_t_c700ff_idx"
                    ),
                    models.Index(
                        fields=["correlation_id", "-occurred_at"],
                        name="stored_even_correla_41c313_idx",
                    ),
                    models.Index(fields=["occurred_at"], name="stored_even_occurre_4402c5_idx"),
                ],
            },
        ),
    ]
