# Generated by Django 4.2.14 on 2024-10-10 15:57

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import forum.utils


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="CommentThread",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("course_id", models.CharField(max_length=255)),
                ("body", models.TextField()),
                ("visible", models.BooleanField(default=True)),
                ("endorsed", models.BooleanField(default=False)),
                ("anonymous", models.BooleanField(default=False)),
                ("anonymous_to_peers", models.BooleanField(default=False)),
                ("group_id", models.PositiveIntegerField(null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("title", models.CharField(max_length=255)),
                (
                    "thread_type",
                    models.CharField(
                        choices=[
                            ("question", "Question"),
                            ("discussion", "Discussion"),
                        ],
                        default="discussion",
                        max_length=50,
                    ),
                ),
                (
                    "context",
                    models.CharField(
                        choices=[("course", "Course"), ("standalone", "Standalone")],
                        default="course",
                        max_length=50,
                    ),
                ),
                ("closed", models.BooleanField(default=False)),
                ("pinned", models.BooleanField(blank=True, null=True)),
                ("last_activity_at", models.DateTimeField(blank=True, null=True)),
                (
                    "close_reason_code",
                    models.CharField(blank=True, max_length=255, null=True),
                ),
                (
                    "commentable_id",
                    models.CharField(
                        blank=True, default=None, max_length=255, null=True
                    ),
                ),
                (
                    "author",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "closed_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="threads_closed",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ReadState",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("course_id", models.CharField(max_length=255, unique=True)),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="read_states",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="LastReadTime",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("timestamp", models.DateTimeField()),
                (
                    "comment_thread",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="forum.commentthread",
                    ),
                ),
                (
                    "read_state",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="last_read_times",
                        to="forum.readstate",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="HistoricalAbuseFlagger",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("content_object_id", models.PositiveIntegerField()),
                ("flagged_at", models.DateTimeField(default=django.utils.timezone.now)),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ForumUser",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("default_sort_key", models.CharField(default="date", max_length=25)),
                (
                    "user",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="forum",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="EditHistory",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "reason_code",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("grammar-spelling", "Has grammar / spelling issues"),
                            ("needs-clarity", "Content needs clarity"),
                            ("academic-integrity", "Has academic integrity concern"),
                            ("inappropriate-language", "Has inappropriate language"),
                            ("format-change", "Formatting changes needed"),
                            ("post-type-change", "Post type needs change"),
                            (
                                "contains-pii",
                                "Contains personally identifiable information",
                            ),
                            ("violates-guidelines", "Violates community guidelines"),
                        ],
                        max_length=100,
                        null=True,
                    ),
                ),
                ("original_body", models.TextField()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("content_object_id", models.PositiveIntegerField()),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "editor",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="CourseStat",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("course_id", models.CharField(max_length=255)),
                ("active_flags", models.IntegerField(default=0)),
                ("inactive_flags", models.IntegerField(default=0)),
                ("threads", models.IntegerField(default=0)),
                ("responses", models.IntegerField(default=0)),
                ("replies", models.IntegerField(default=0)),
                (
                    "last_activity_at",
                    models.DateTimeField(blank=True, default=None, null=True),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="course_stats",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Comment",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("course_id", models.CharField(max_length=255)),
                ("body", models.TextField()),
                ("visible", models.BooleanField(default=True)),
                ("endorsed", models.BooleanField(default=False)),
                ("anonymous", models.BooleanField(default=False)),
                ("anonymous_to_peers", models.BooleanField(default=False)),
                ("group_id", models.PositiveIntegerField(null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("endorsement", models.JSONField(default=dict)),
                ("sort_key", models.CharField(blank=True, max_length=255, null=True)),
                ("child_count", models.PositiveIntegerField(default=0)),
                (
                    "retired_username",
                    models.CharField(blank=True, max_length=255, null=True),
                ),
                ("depth", models.PositiveIntegerField(default=0)),
                (
                    "author",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "comment_thread",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="forum.commentthread",
                    ),
                ),
                (
                    "parent",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="forum.comment",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="AbuseFlagger",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("content_object_id", models.PositiveIntegerField()),
                ("flagged_at", models.DateTimeField(default=django.utils.timezone.now)),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="UserVote",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("content_object_id", models.PositiveIntegerField()),
                (
                    "vote",
                    models.IntegerField(
                        validators=[forum.utils.validate_upvote_or_downvote]
                    ),
                ),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(fields=["vote"], name="forum_userv_vote_2ccbcf_idx"),
                    models.Index(
                        fields=["user", "vote"], name="forum_userv_user_id_7ab0c3_idx"
                    ),
                    models.Index(
                        fields=["content_type", "content_object_id"],
                        name="forum_userv_content_55d9ad_idx",
                    ),
                ],
                "unique_together": {("user", "content_type", "content_object_id")},
            },
        ),
        migrations.CreateModel(
            name="Subscription",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("source_object_id", models.PositiveIntegerField()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "source_content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "subscriber",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["subscriber"], name="forum_subsc_subscri_34fd6c_idx"
                    ),
                    models.Index(
                        fields=[
                            "subscriber",
                            "source_object_id",
                            "source_content_type",
                        ],
                        name="forum_subsc_subscri_77168d_idx",
                    ),
                    models.Index(
                        fields=["subscriber", "source_content_type"],
                        name="forum_subsc_subscri_a64d92_idx",
                    ),
                    models.Index(
                        fields=["source_object_id", "source_content_type"],
                        name="forum_subsc_source__ef74be_idx",
                    ),
                ],
                "unique_together": {
                    ("subscriber", "source_content_type", "source_object_id")
                },
            },
        ),
        migrations.AddIndex(
            model_name="readstate",
            index=models.Index(
                fields=["user", "course_id"], name="forum_reads_user_id_30cd0a_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="readstate",
            unique_together={("course_id", "user")},
        ),
        migrations.AddIndex(
            model_name="lastreadtime",
            index=models.Index(
                fields=["read_state", "timestamp"],
                name="forum_lastr_read_st_67a4f9_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="lastreadtime",
            index=models.Index(
                fields=["comment_thread"], name="forum_lastr_comment_652102_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="lastreadtime",
            unique_together={("read_state", "timestamp")},
        ),
        migrations.AddIndex(
            model_name="historicalabuseflagger",
            index=models.Index(
                fields=["content_type", "content_object_id"],
                name="forum_histo_content_e4456d_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="historicalabuseflagger",
            index=models.Index(
                fields=["user", "content_type", "content_object_id"],
                name="forum_histo_user_id_761c88_idx",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="historicalabuseflagger",
            unique_together={("user", "content_type", "content_object_id")},
        ),
        migrations.AddIndex(
            model_name="edithistory",
            index=models.Index(
                fields=["editor"], name="forum_edith_editor__159ea4_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="edithistory",
            index=models.Index(
                fields=["content_type", "content_object_id"],
                name="forum_edith_content_3e9471_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="edithistory",
            index=models.Index(
                fields=["created_at"], name="forum_edith_created_67bba8_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="coursestat",
            unique_together={("user", "course_id")},
        ),
        migrations.AddIndex(
            model_name="commentthread",
            index=models.Index(
                fields=["context"], name="forum_comme_context_cfe3d0_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="commentthread",
            index=models.Index(
                fields=["author"], name="forum_comme_author__04774e_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="commentthread",
            index=models.Index(
                fields=["author", "course_id"], name="forum_comme_author__e6f558_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="commentthread",
            index=models.Index(
                fields=["course_id", "anonymous", "anonymous_to_peers"],
                name="forum_comme_course__c529cf_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="commentthread",
            index=models.Index(
                fields=["author", "course_id", "anonymous", "anonymous_to_peers"],
                name="forum_comme_author__8df595_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="comment",
            index=models.Index(
                fields=["author", "course_id"], name="forum_comme_author__257002_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="comment",
            index=models.Index(
                fields=["comment_thread", "author", "created_at"],
                name="forum_comme_comment_5e5849_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="comment",
            index=models.Index(
                fields=["comment_thread", "endorsed"],
                name="forum_comme_comment_4f1303_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="comment",
            index=models.Index(
                fields=["course_id", "parent", "endorsed"],
                name="forum_comme_course__333a3b_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="comment",
            index=models.Index(
                fields=["course_id", "anonymous", "anonymous_to_peers"],
                name="forum_comme_course__fc7371_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="comment",
            index=models.Index(
                fields=["author", "course_id", "anonymous", "anonymous_to_peers"],
                name="forum_comme_author__084b35_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="abuseflagger",
            index=models.Index(
                fields=["content_type", "content_object_id"],
                name="forum_abuse_content_b190f5_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="abuseflagger",
            index=models.Index(
                fields=["user", "content_type", "content_object_id"],
                name="forum_abuse_user_id_8f5d27_idx",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="abuseflagger",
            unique_together={("user", "content_type", "content_object_id")},
        ),
    ]
