# Generated by Django 3.1.7 on 2024-01-27 04:37

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


class Migration(migrations.Migration):

    dependencies = [
        ("repository", "0048_populate_visibility"),
    ]

    operations = [
        migrations.CreateModel(
            name="PackageInstaller",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("identifier", models.SlugField(editable=False, unique=True)),
            ],
        ),
        migrations.CreateModel(
            name="PackageInstallerDeclaration",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
            ],
        ),
        migrations.RemoveConstraint(
            model_name="packageversion",
            name="valid_package_format",
        ),
        migrations.AlterField(
            model_name="packageversion",
            name="format_spec",
            field=models.TextField(
                blank=True,
                choices=[
                    ("thunderstore.io:v0.0", "V0 0"),
                    ("thunderstore.io:v0.1", "V0 1"),
                    ("thunderstore.io:v0.2", "V0 2"),
                    ("thunderstore.io:v0.3", "V0 3"),
                ],
                help_text="Used to track the latest package format spec this package is compatible with",
                null=True,
            ),
        ),
        migrations.AddConstraint(
            model_name="packageversion",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("format_spec", None),
                    ("format_spec", "thunderstore.io:v0.0"),
                    ("format_spec", "thunderstore.io:v0.1"),
                    ("format_spec", "thunderstore.io:v0.2"),
                    ("format_spec", "thunderstore.io:v0.3"),
                    _connector="OR",
                ),
                name="valid_package_format",
            ),
        ),
        migrations.AddField(
            model_name="packageinstallerdeclaration",
            name="package_installer",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="installer_declarations",
                to="repository.packageinstaller",
            ),
        ),
        migrations.AddField(
            model_name="packageinstallerdeclaration",
            name="package_version",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="installer_declarations",
                to="repository.packageversion",
            ),
        ),
        migrations.AddField(
            model_name="packageversion",
            name="installers",
            field=models.ManyToManyField(
                blank=True,
                related_name="package_versions",
                through="repository.PackageInstallerDeclaration",
                to="repository.PackageInstaller",
            ),
        ),
    ]
