# Generated by Django 4.1 on 2022-08-31 07:09

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


class Migration(migrations.Migration):

    dependencies = [
        ("scanpipe", "0021_codebaseresource_package_data"),
    ]

    operations = [
        migrations.RenameField(
            model_name='discoveredpackage',
            old_name='dependencies',
            new_name='dependencies_data',
        ),
        migrations.CreateModel(
            name="DiscoveredDependency",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "type",
                    models.CharField(
                        blank=True,
                        help_text="A short code to identify the type of this package. For example: gem for a Rubygem, docker for a container, pypi for a Python Wheel or Egg, maven for a Maven Jar, deb for a Debian package, etc.",
                        max_length=16,
                    ),
                ),
                (
                    "namespace",
                    models.CharField(
                        blank=True,
                        help_text="Package name prefix, such as Maven groupid, Docker image owner, GitHub user or organization, etc.",
                        max_length=255,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        blank=True, help_text="Name of the package.", max_length=100
                    ),
                ),
                (
                    "version",
                    models.CharField(
                        blank=True, help_text="Version of the package.", max_length=100
                    ),
                ),
                (
                    "qualifiers",
                    models.CharField(
                        blank=True,
                        help_text="Extra qualifying data for a package such as the name of an OS, architecture, distro, etc.",
                        max_length=1024,
                    ),
                ),
                (
                    "subpath",
                    models.CharField(
                        blank=True,
                        help_text="Extra subpath within a package, relative to the package root.",
                        max_length=200,
                    ),
                ),
                (
                    "dependency_uid",
                    models.CharField(
                        help_text="The unique identifier of this dependency.",
                        max_length=1024,
                    ),
                ),
                (
                    "extracted_requirement",
                    models.CharField(
                        blank=True,
                        help_text="The version requirements of this dependency.",
                        max_length=256,
                    ),
                ),
                (
                    "scope",
                    models.CharField(
                        blank=True,
                        help_text="The scope of this dependency, how it is used in a project.",
                        max_length=64,
                    ),
                ),
                (
                    "datasource_id",
                    models.CharField(
                        blank=True,
                        help_text="The identifier for the datafile handler used to obtain this dependency.",
                        max_length=64,
                    ),
                ),
                ("is_runtime", models.BooleanField(default=False)),
                ("is_optional", models.BooleanField(default=False)),
                ("is_resolved", models.BooleanField(default=False)),
                (
                    "datafile_resource",
                    models.ForeignKey(
                        blank=True,
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dependencies",
                        to="scanpipe.codebaseresource",
                    ),
                ),
                (
                    "for_package",
                    models.ForeignKey(
                        blank=True,
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dependencies",
                        to="scanpipe.discoveredpackage",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        editable=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="discovereddependencies",
                        to="scanpipe.project",
                    ),
                ),
            ],
            options={
                "verbose_name": "discovered dependency",
                "verbose_name_plural": "discovered dependencies",
                "ordering": [
                    "-is_runtime",
                    "-is_resolved",
                    "is_optional",
                    "dependency_uid",
                    "for_package",
                    "datafile_resource",
                    "datasource_id",
                ],
            },
            bases=(
                scanpipe.models.SaveProjectMessageMixin,
                scanpipe.models.UpdateFromDataMixin,
                models.Model,
            ),
        ),
        migrations.AddConstraint(
            model_name="discovereddependency",
            constraint=models.UniqueConstraint(
                condition=models.Q(("dependency_uid", ""), _negated=True),
                fields=("project", "dependency_uid"),
                name="scanpipe_discovereddependency_unique_dependency_uid_within_project",
            ),
        ),
    ]
