# Generated by Django 5.2.13 on 2026-04-24 06:03

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="UpstreamEvent",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "module",
                    models.CharField(
                        choices=[
                            ("rims", "RIMS"),
                            ("rep", "REP"),
                            ("repository", "Repository"),
                            ("smehub", "SME-Hub"),
                            ("alumni", "Alumni"),
                        ],
                        db_index=True,
                        max_length=16,
                    ),
                ),
                ("event_type", models.CharField(db_index=True, max_length=64)),
                ("source_object_id", models.CharField(db_index=True, max_length=64)),
                ("payload", models.JSONField(blank=True, default=dict)),
                ("recorded_at", models.DateTimeField(auto_now_add=True)),
                (
                    "subject",
                    models.ForeignKey(
                        blank=True,
                        help_text="Person the event is about, when identifiable.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="mel_upstream_events",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-recorded_at"],
                "indexes": [
                    models.Index(
                        fields=["module", "event_type", "recorded_at"],
                        name="mel_trackin_module_c03241_idx",
                    )
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("module", "event_type", "source_object_id"),
                        name="uniq_upstream_event",
                    )
                ],
            },
        ),
    ]
