# Copyright (C) 2011-2023 Linaro Limited
# Copyright (C) 2023 Collabora Limited
#
# Author: Igor Ponomarev <igor.ponomarev@collabora.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Squashed by Igor Ponomarev <igor.ponomarev@collabora.com>
# Derived from the following migrations and their authors:
#
# 0001_initial                         - Michael-Doyle Hudson <michael.hudson@linaro.org>
# 0002_add_lava-health_user            - Neil Williams <neil.williams@linaro.org>
# 0003_populate_master_node            - Senthil Kumaran S <senthil.kumaran@linaro.org>
# 0004_add_pipeline_marks              - Rémi Duraffort <remi.duraffort@linaro.org>
# 0005-0012                            - Neil Williams / Senthil Kumaran S
# 0013                                 - Senthil Kumaran S <senthil.kumaran@linaro.org>
# 0014, 0016                           - Rémi Duraffort <remi.duraffort@linaro.org>
# 0015, 0017, 0022, 0023               - Neil Williams <neil.williams@linaro.org>
# 0018-0021                            - Stevan Radaković <stevan.radakovic@linaro.org>
# 0024, 0026                           - Rémi Duraffort <remi.duraffort@linaro.org>
# 0025                                 - Stevan Radakovic <stevan.radakovic@linaro.org>
# 0026_devicetype_disable_health_check - Rémi Duraffort <remi.duraffort@linaro.org>

# Generated by Django 2.2.28 on 2023-12-18 10:40

import django.db.models.deletion
from django.conf import settings
from django.contrib.auth.hashers import make_password
from django.db import migrations, models, transaction
from django.utils import timezone

import lava_scheduler_app.dbutils


def create_lava_health(apps, schema_editor):
    User = apps.get_model("auth", "User")
    db_alias = schema_editor.connection.alias
    now = timezone.now()
    with transaction.atomic():
        new_user = User.objects.using(db_alias).create(
            username="lava-health",
            email="lava@lava.invalid",
            is_staff=False,
            is_active=True,
            is_superuser=False,
            last_login=now,
            date_joined=now,
            password=make_password(None),  # Make unusable password
            # Because of historical models the set_unusable_password()
            # is not available.
        )
        new_user.save()


class Migration(migrations.Migration):
    replaces = [
        ("lava_scheduler_app", "0001_initial"),
        ("lava_scheduler_app", "0002_add_lava-health_user"),
        ("lava_scheduler_app", "0003_populate_master_node"),
        ("lava_scheduler_app", "0004_add_pipeline_marks"),
        ("lava_scheduler_app", "0005_auto_devicedictionarytable_pipelinestore"),
        ("lava_scheduler_app", "0006_auto_20150619_1035"),
        ("lava_scheduler_app", "0007_devicetype_description"),
        ("lava_scheduler_app", "0008_auto_20151014_1044"),
        ("lava_scheduler_app", "0009_testjob_pipeline_compatibility"),
        ("lava_scheduler_app", "0010_auto_20151103_1136"),
        ("lava_scheduler_app", "0011_remove_testjob_log_file"),
        ("lava_scheduler_app", "0012_auto_20160208_1600"),
        ("lava_scheduler_app", "0013_auto_20160302_0404"),
        ("lava_scheduler_app", "0014_add_testjob_index"),
        ("lava_scheduler_app", "0015_drop_heartbeat"),
        ("lava_scheduler_app", "0016_index_testjob_submit_time"),
        ("lava_scheduler_app", "0017_custompermissions"),
        ("lava_scheduler_app", "0018_notifications"),
        ("lava_scheduler_app", "0019_extendeduser"),
        ("lava_scheduler_app", "0020_notificationrecipient_uniquetogether"),
        ("lava_scheduler_app", "0021_blacklist_to_array"),
        ("lava_scheduler_app", "0022_create_devicetype_alias"),
        ("lava_scheduler_app", "0023_update_aliases"),
        ("lava_scheduler_app", "0024_do_not_cascade_deletions"),
        ("lava_scheduler_app", "0025_switch_job_status_trigger_type"),
        ("lava_scheduler_app", "0026_devicetype_disable_health_check"),
    ]

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("contenttypes", "0002_remove_content_type_name"),
        ("linaro_django_xmlrpc", "__first__"),
        ("auth", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="DefaultDeviceOwner",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "default_owner",
                    models.BooleanField(
                        default=False,
                        unique=True,
                        verbose_name="Default owner of unrestricted devices",
                    ),
                ),
                (
                    "user",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Device",
            fields=[
                ("is_public", models.BooleanField(default=False)),
                (
                    "hostname",
                    models.CharField(
                        max_length=200,
                        primary_key=True,
                        serialize=False,
                        verbose_name="Hostname",
                    ),
                ),
                (
                    "device_version",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=200,
                        null=True,
                        verbose_name="Device Version",
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        default=None,
                        max_length=200,
                        null=True,
                        verbose_name="Device Description",
                    ),
                ),
                (
                    "status",
                    models.IntegerField(
                        choices=[
                            (0, "Offline"),
                            (1, "Idle"),
                            (2, "Running"),
                            (3, "Going offline"),
                            (4, "Retired"),
                            (5, "Reserved"),
                        ],
                        default=1,
                        verbose_name="Device status",
                    ),
                ),
                (
                    "health_status",
                    models.IntegerField(
                        choices=[
                            (0, "Unknown"),
                            (1, "Pass"),
                            (2, "Fail"),
                            (3, "Looping"),
                        ],
                        default=0,
                        verbose_name="Device Health",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="DeviceType",
            fields=[
                ("name", models.SlugField(primary_key=True, serialize=False)),
                (
                    "health_check_job",
                    models.TextField(blank=True, default=None, null=True),
                ),
                (
                    "display",
                    models.BooleanField(
                        default=True,
                        help_text="Should this be displayed in the GUI or not. This can be useful if you are removing all devices of this type but don't want to loose the test results generated by the devices.",
                    ),
                ),
                (
                    "owners_only",
                    models.BooleanField(
                        default=False,
                        help_text="Hide this device type for all users except owners of devices of this type.",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="JobFailureTag",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=256, unique=True)),
                ("description", models.TextField(blank=True, null=True)),
            ],
        ),
        migrations.CreateModel(
            name="Tag",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.SlugField(unique=True)),
                ("description", models.TextField(blank=True, null=True)),
            ],
        ),
        migrations.CreateModel(
            name="TemporaryDevice",
            fields=[
                (
                    "device_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="lava_scheduler_app.Device",
                    ),
                ),
                (
                    "vm_group",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=64,
                        null=True,
                        verbose_name="VM Group",
                    ),
                ),
            ],
            bases=("lava_scheduler_app.device",),
        ),
        migrations.CreateModel(
            name="TestJob",
            fields=[
                ("is_public", models.BooleanField(default=False)),
                ("id", models.AutoField(primary_key=True, serialize=False)),
                (
                    "sub_id",
                    models.CharField(blank=True, max_length=200, verbose_name="Sub ID"),
                ),
                (
                    "target_group",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=64,
                        null=True,
                        verbose_name="Target Group",
                    ),
                ),
                (
                    "vm_group",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=64,
                        null=True,
                        verbose_name="VM Group",
                    ),
                ),
                (
                    "description",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=200,
                        null=True,
                        verbose_name="Description",
                    ),
                ),
                ("health_check", models.BooleanField(default=False)),
                (
                    "submit_time",
                    models.DateTimeField(auto_now_add=True, verbose_name="Submit time"),
                ),
                (
                    "start_time",
                    models.DateTimeField(
                        blank=True, editable=False, null=True, verbose_name="Start time"
                    ),
                ),
                (
                    "end_time",
                    models.DateTimeField(
                        blank=True, editable=False, null=True, verbose_name="End time"
                    ),
                ),
                (
                    "status",
                    models.IntegerField(
                        choices=[
                            (0, "Submitted"),
                            (1, "Running"),
                            (2, "Complete"),
                            (3, "Incomplete"),
                            (4, "Canceled"),
                            (5, "Canceling"),
                        ],
                        default=0,
                        verbose_name="Status",
                    ),
                ),
                (
                    "priority",
                    models.IntegerField(
                        choices=[(0, "Low"), (50, "Medium"), (100, "High")],
                        default=50,
                        verbose_name="Priority",
                    ),
                ),
                ("definition", models.TextField(editable=False)),
                ("original_definition", models.TextField(blank=True, editable=False)),
                ("multinode_definition", models.TextField(blank=True, editable=False)),
                ("vmgroup_definition", models.TextField(blank=True, editable=False)),
                ("admin_notifications", models.TextField(blank=True, editable=False)),
                (
                    "log_file",
                    models.FileField(
                        blank=True, default=None, null=True, upload_to="lava-logs"
                    ),
                ),
                ("failure_comment", models.TextField(blank=True, null=True)),
                (
                    "_results_link",
                    models.CharField(
                        blank=True,
                        db_column="results_link",
                        default=None,
                        max_length=400,
                        null=True,
                    ),
                ),
                (
                    "actual_device",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="lava_scheduler_app.Device",
                    ),
                ),
                (
                    "failure_tags",
                    models.ManyToManyField(
                        blank=True,
                        related_name="failure_tags",
                        to="lava_scheduler_app.JobFailureTag",
                    ),
                ),
                (
                    "group",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="auth.Group",
                    ),
                ),
                (
                    "requested_device",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="lava_scheduler_app.Device",
                    ),
                ),
                (
                    "requested_device_type",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="lava_scheduler_app.DeviceType",
                    ),
                ),
                (
                    "submit_token",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="linaro_django_xmlrpc.AuthToken",
                    ),
                ),
                (
                    "submitter",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Submitter",
                    ),
                ),
                (
                    "tags",
                    models.ManyToManyField(blank=True, to="lava_scheduler_app.Tag"),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Worker",
            fields=[
                (
                    "hostname",
                    models.CharField(
                        default=None,
                        editable=False,
                        max_length=200,
                        primary_key=True,
                        serialize=False,
                        verbose_name="Hostname",
                    ),
                ),
                (
                    "rpc2_url",
                    models.CharField(
                        blank=True,
                        default=None,
                        help_text="Corresponds to the master node's RPC2 url. Does not have any impact when set on a worker node.",
                        max_length=200,
                        null=True,
                        verbose_name="Master RPC2 URL",
                    ),
                ),
                (
                    "display",
                    models.BooleanField(
                        default=True,
                        help_text="Should this be displayed in the GUI or not. This will be useful when a worker needs to be removed but still linked device status transitions and devices should be intact.",
                    ),
                ),
                (
                    "ip_address",
                    models.CharField(
                        blank=True,
                        default=None,
                        editable=False,
                        max_length=20,
                        null=True,
                        verbose_name="IP Address",
                    ),
                ),
                (
                    "is_master",
                    models.BooleanField(default=False, verbose_name="Is Master?"),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        default=None,
                        max_length=200,
                        null=True,
                        verbose_name="Worker Description",
                    ),
                ),
                (
                    "uptime",
                    models.CharField(
                        blank=True,
                        default=None,
                        editable=False,
                        max_length=200,
                        null=True,
                        verbose_name="Host Uptime",
                    ),
                ),
                (
                    "arch",
                    models.CharField(
                        blank=True,
                        default=None,
                        editable=False,
                        max_length=200,
                        null=True,
                        verbose_name="Architecture",
                    ),
                ),
                (
                    "platform",
                    models.CharField(
                        blank=True,
                        default=None,
                        editable=False,
                        max_length=200,
                        null=True,
                        verbose_name="Platform",
                    ),
                ),
                (
                    "hardware_info",
                    models.TextField(
                        blank=True,
                        editable=False,
                        verbose_name="Complete Hardware Information",
                    ),
                ),
                (
                    "software_info",
                    models.TextField(
                        blank=True,
                        editable=False,
                        verbose_name="Complete Software Information",
                    ),
                ),
                (
                    "last_heartbeat",
                    models.DateTimeField(
                        blank=True,
                        editable=False,
                        null=True,
                        verbose_name="Last Heartbeat",
                    ),
                ),
                (
                    "last_master_scheduler_tick",
                    models.DateTimeField(
                        blank=True,
                        editable=False,
                        help_text="Corresponds to the master node's last scheduler tick. Does not have any impact when set on a worker node.",
                        null=True,
                        verbose_name="Last Master Scheduler Tick",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="TestJobUser",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "is_favorite",
                    models.BooleanField(default=False, verbose_name="Favorite job"),
                ),
                (
                    "test_job",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="lava_scheduler_app.TestJob",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "unique_together": {("test_job", "user")},
            },
        ),
        migrations.CreateModel(
            name="DeviceStateTransition",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_on", models.DateTimeField(auto_now_add=True)),
                (
                    "old_state",
                    models.IntegerField(
                        choices=[
                            (0, "Offline"),
                            (1, "Idle"),
                            (2, "Running"),
                            (3, "Going offline"),
                            (4, "Retired"),
                            (5, "Reserved"),
                        ]
                    ),
                ),
                (
                    "new_state",
                    models.IntegerField(
                        choices=[
                            (0, "Offline"),
                            (1, "Idle"),
                            (2, "Running"),
                            (3, "Going offline"),
                            (4, "Retired"),
                            (5, "Reserved"),
                        ]
                    ),
                ),
                ("message", models.TextField(blank=True, null=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "device",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="transitions",
                        to="lava_scheduler_app.Device",
                    ),
                ),
                (
                    "job",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="lava_scheduler_app.TestJob",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="device",
            name="current_job",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="+",
                to="lava_scheduler_app.TestJob",
                unique=True,
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="device_type",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                to="lava_scheduler_app.DeviceType",
                verbose_name="Device type",
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="group",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="auth.Group",
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="last_health_report_job",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="+",
                to="lava_scheduler_app.TestJob",
                unique=True,
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="physical_group",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="physical-group",
                to="auth.Group",
                verbose_name="Group with physical access",
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="physical_owner",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="physical-owner",
                to=settings.AUTH_USER_MODEL,
                verbose_name="User with physical access",
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="tags",
            field=models.ManyToManyField(blank=True, to="lava_scheduler_app.Tag"),
        ),
        migrations.AddField(
            model_name="device",
            name="user",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="device",
            name="worker_host",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="lava_scheduler_app.Worker",
                verbose_name="Worker Host",
            ),
        ),
        migrations.RunPython(
            code=create_lava_health,
        ),
        migrations.CreateModel(
            name="DeviceDictionaryTable",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("kee", models.CharField(max_length=255)),
                ("value", models.TextField()),
            ],
        ),
        migrations.CreateModel(
            name="PipelineStore",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("kee", models.CharField(max_length=255)),
                ("value", models.TextField()),
            ],
        ),
        migrations.AddField(
            model_name="device",
            name="is_pipeline",
            field=models.BooleanField(default=False, verbose_name="Pipeline device?"),
        ),
        migrations.AddField(
            model_name="testjob",
            name="is_pipeline",
            field=models.BooleanField(
                default=False, editable=False, verbose_name="Pipeline job?"
            ),
        ),
        migrations.CreateModel(
            name="Architecture",
            fields=[
                (
                    "name",
                    models.CharField(
                        help_text="e.g. ARMv7",
                        max_length=100,
                        primary_key=True,
                        serialize=False,
                        verbose_name="Architecture version",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="BitWidth",
            fields=[
                (
                    "width",
                    models.PositiveSmallIntegerField(
                        help_text="integer: e.g. 32 or 64",
                        primary_key=True,
                        serialize=False,
                        verbose_name="Processor bit width",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Core",
            fields=[
                (
                    "name",
                    models.CharField(
                        help_text="Name of a specific CPU core, e.g. Cortex-A9",
                        max_length=100,
                        primary_key=True,
                        serialize=False,
                        verbose_name="CPU core",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ProcessorFamily",
            fields=[
                (
                    "name",
                    models.CharField(
                        help_text="e.g. OMAP4, Exynos",
                        max_length=100,
                        primary_key=True,
                        serialize=False,
                        verbose_name="Processor Family",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="devicetype",
            name="core_count",
            field=models.PositiveSmallIntegerField(
                blank=True,
                help_text="Must be an equal number of each type(s) of core(s).",
                null=True,
                verbose_name="Total number of cores",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="cpu_model",
            field=models.CharField(
                blank=True,
                help_text="e.g. a list of CPU model descriptive strings: OMAP4430 / OMAP4460",
                max_length=100,
                null=True,
                verbose_name="CPU model",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="description",
            field=models.TextField(
                blank=True,
                default=None,
                max_length=200,
                null=True,
                verbose_name="Device Type Description",
            ),
        ),
        migrations.AddField(
            model_name="testjob",
            name="viewing_groups",
            field=models.ManyToManyField(
                blank=True,
                default=None,
                help_text="Adding groups to an intersection of groups reduces visibility.Adding groups to a union of groups expands visibility.",
                related_name="viewing_groups",
                to="auth.Group",
                verbose_name="Viewing groups",
            ),
        ),
        migrations.AddField(
            model_name="testjob",
            name="visibility",
            field=models.IntegerField(
                choices=[
                    (0, "Publicly visible"),
                    (1, "Personal only"),
                    (2, "Group only"),
                ],
                default=0,
                help_text="Visibility affects the TestJob and all results arising from that job, including Queries and Reports.",
                verbose_name="Visibility type",
            ),
        ),
        migrations.AddField(
            model_name="testjob",
            name="pipeline_compatibility",
            field=models.IntegerField(default=0, editable=False),
        ),
        migrations.AlterField(
            model_name="device",
            name="current_job",
            field=models.OneToOneField(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="+",
                to="lava_scheduler_app.TestJob",
            ),
        ),
        migrations.AlterField(
            model_name="device",
            name="last_health_report_job",
            field=models.OneToOneField(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="+",
                to="lava_scheduler_app.TestJob",
            ),
        ),
        migrations.AlterField(
            model_name="device",
            name="physical_group",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="physicalgroup",
                to="auth.Group",
                verbose_name="Group with physical access",
            ),
        ),
        migrations.AlterField(
            model_name="device",
            name="physical_owner",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="physicalowner",
                to=settings.AUTH_USER_MODEL,
                verbose_name="User with physical access",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="cores",
            field=models.ManyToManyField(
                blank=True, related_name="device_types", to="lava_scheduler_app.Core"
            ),
        ),
        migrations.RemoveField(
            model_name="testjob",
            name="log_file",
        ),
        migrations.AddField(
            model_name="devicetype",
            name="health_frequency",
            field=models.IntegerField(
                default=24, verbose_name="How often to run health checks"
            ),
        ),
        migrations.AlterField(
            model_name="devicetype",
            name="health_check_job",
            field=models.TextField(
                blank=True,
                default=None,
                null=True,
                validators=[lava_scheduler_app.dbutils.validate_job],
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="health_denominator",
            field=models.IntegerField(
                choices=[(0, "hours"), (1, "jobs")],
                default=0,
                help_text="Choose to submit a health check every N hours or every N jobs. Balance against the duration of a health check job and the average job duration.",
                verbose_name="Initiate health checks by hours or by jobs.",
            ),
        ),
        migrations.AlterIndexTogether(
            name="testjob",
            index_together={("status", "requested_device_type", "requested_device")},
        ),
        migrations.RemoveField(
            model_name="worker",
            name="arch",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="hardware_info",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="ip_address",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="last_heartbeat",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="last_master_scheduler_tick",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="platform",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="software_info",
        ),
        migrations.RemoveField(
            model_name="worker",
            name="uptime",
        ),
        migrations.AlterField(
            model_name="worker",
            name="hostname",
            field=models.CharField(
                default=None,
                max_length=200,
                primary_key=True,
                serialize=False,
                verbose_name="Hostname",
            ),
        ),
        migrations.AlterField(
            model_name="testjob",
            name="submit_time",
            field=models.DateTimeField(
                auto_now_add=True, db_index=True, verbose_name="Submit time"
            ),
        ),
        migrations.AlterModelOptions(
            name="testjobuser",
            options={
                "permissions": (
                    ("cancel_resubmit_testjob", "Can cancel or resubmit test jobs"),
                )
            },
        ),
        migrations.CreateModel(
            name="Notification",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "type",
                    models.IntegerField(
                        blank=True,
                        choices=[(0, "regression"), (1, "progression")],
                        default=None,
                        null=True,
                        verbose_name="Type",
                    ),
                ),
                (
                    "job_status_trigger",
                    models.CharField(
                        choices=[
                            (0, "Submitted"),
                            (1, "Running"),
                            (2, "Complete"),
                            (3, "Incomplete"),
                            (4, "Canceled"),
                            (5, "Canceling"),
                        ],
                        default=2,
                        max_length=30,
                        verbose_name="Job status trigger",
                    ),
                ),
                (
                    "verbosity",
                    models.IntegerField(
                        choices=[(0, "verbose"), (1, "quiet"), (2, "status-only")],
                        default=1,
                    ),
                ),
                (
                    "template",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=50,
                        null=True,
                        verbose_name="Template name",
                    ),
                ),
                (
                    "time_sent",
                    models.DateTimeField(auto_now_add=True, verbose_name="Time sent"),
                ),
                (
                    "query_name",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=1024,
                        null=True,
                        verbose_name="Query name",
                    ),
                ),
                (
                    "conditions",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=400,
                        null=True,
                        verbose_name="Conditions",
                    ),
                ),
                (
                    "entity",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.ContentType",
                    ),
                ),
                (
                    "query_owner",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Query owner",
                    ),
                ),
                (
                    "test_job",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="lava_scheduler_app.TestJob",
                    ),
                ),
                (
                    "blacklist",
                    models.JSONField(blank=True, default=list, null=True),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ExtendedUser",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "irc_handle",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=40,
                        null=True,
                        verbose_name="IRC handle",
                    ),
                ),
                (
                    "irc_server",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=40,
                        null=True,
                        verbose_name="IRC server",
                    ),
                ),
                (
                    "user",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="NotificationRecipient",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "email",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=100,
                        null=True,
                        verbose_name="recipient email",
                    ),
                ),
                (
                    "irc_handle",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=40,
                        null=True,
                        verbose_name="IRC handle",
                    ),
                ),
                (
                    "irc_server",
                    models.CharField(
                        blank=True,
                        default=None,
                        max_length=40,
                        null=True,
                        verbose_name="IRC server",
                    ),
                ),
                (
                    "status",
                    models.IntegerField(
                        choices=[(0, "sent"), (1, "not sent")],
                        default=1,
                        verbose_name="Status",
                    ),
                ),
                (
                    "method",
                    models.IntegerField(
                        choices=[(0, "email"), (1, "irc")],
                        default=0,
                        verbose_name="Method",
                    ),
                ),
                (
                    "notification",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="lava_scheduler_app.Notification",
                        verbose_name="Notification",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Notification user recipient",
                    ),
                ),
            ],
            options={
                "unique_together": {("user", "notification", "method")},
            },
        ),
        migrations.CreateModel(
            name="Alias",
            fields=[
                (
                    "name",
                    models.CharField(
                        help_text="e.g. the device tree name(s)",
                        max_length=200,
                        primary_key=True,
                        serialize=False,
                        verbose_name="Alias for this device-type",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="devicetype",
            name="aliases",
            field=models.ManyToManyField(
                blank=True, related_name="device_types", to="lava_scheduler_app.Alias"
            ),
        ),
        migrations.AlterField(
            model_name="device",
            name="physical_owner",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="physicalowner",
                to=settings.AUTH_USER_MODEL,
                verbose_name="User with physical access",
            ),
        ),
        migrations.AlterField(
            model_name="device",
            name="worker_host",
            field=models.ForeignKey(
                blank=True,
                default=None,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to="lava_scheduler_app.Worker",
                verbose_name="Worker Host",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="architecture",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="device_types",
                to="lava_scheduler_app.Architecture",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="bits",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="device_types",
                to="lava_scheduler_app.BitWidth",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="processor",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="device_types",
                to="lava_scheduler_app.ProcessorFamily",
            ),
        ),
        migrations.AddField(
            model_name="devicetype",
            name="disable_health_check",
            field=models.BooleanField(
                default=False,
                verbose_name="Disable health check for devices of this type",
            ),
        ),
    ]
