# Generated by Django 3.1.7 on 2023-07-30 07:35

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

import thunderstore.schema_server.models.file
import thunderstore.utils.makemigrations


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name="SchemaChannel",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("datetime_created", models.DateTimeField(auto_now_add=True)),
                ("datetime_updated", models.DateTimeField(auto_now=True)),
                ("identifier", models.SlugField(max_length=128, unique=True)),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="SchemaChannelFile",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("datetime_created", models.DateTimeField(auto_now_add=True)),
                ("datetime_updated", models.DateTimeField(auto_now=True)),
                ("is_active", models.BooleanField(default=True)),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="SchemaFile",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("content_type", models.TextField()),
                ("content_encoding", models.TextField()),
                ("last_modified", models.DateTimeField()),
                ("is_deleted", models.BooleanField(default=False)),
                (
                    "data",
                    models.FileField(
                        blank=True,
                        editable=False,
                        null=True,
                        storage=thunderstore.utils.makemigrations.StubStorage(),
                        upload_to=thunderstore.schema_server.models.file.get_schema_file_path,
                    ),
                ),
                (
                    "checksum_sha256",
                    models.CharField(
                        db_index=True, editable=False, max_length=512, unique=True
                    ),
                ),
                ("file_size", models.PositiveIntegerField()),
                ("gzip_size", models.PositiveBigIntegerField()),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddIndex(
            model_name="schemafile",
            index=models.Index(
                fields=["last_modified"], name="schema_serv_last_mo_c6fcbe_idx"
            ),
        ),
        migrations.AddField(
            model_name="schemachannelfile",
            name="channel",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="channel_files",
                to="schema_server.schemachannel",
            ),
        ),
        migrations.AddField(
            model_name="schemachannelfile",
            name="file",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="channel_files",
                to="schema_server.schemafile",
            ),
        ),
        migrations.AddField(
            model_name="schemachannel",
            name="authorized_users",
            field=models.ManyToManyField(
                related_name="schema_channels", to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AddField(
            model_name="schemachannel",
            name="latest",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="+",
                to="schema_server.schemachannelfile",
            ),
        ),
    ]
