# Generated by Django 4.2.5 on 2023-10-11 13:18

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

import lnschema_core.ids
import lnschema_core.models
import lnschema_core.types
import lnschema_core.users


class Migration(migrations.Migration):
    replaces = [
        ("lnschema_core", "0001_initial"),
        ("lnschema_core", "0002_alter_user_name"),
        ("lnschema_core", "0003_alter_storage_region_alter_transform_short_name"),
        ("lnschema_core", "0004_rename_folder_tag_alter_project_folders"),
        ("lnschema_core", "0005_alter_run_inputs_delete_runinput"),
        ("lnschema_core", "0006_feature_dataset"),
        ("lnschema_core", "0007_feature_synonyms_featureset_field_and_more"),
        ("lnschema_core", "0008_file_hash_type_transform_parents"),
        ("lnschema_core", "0009_remove_featureset_files_feature_unit_and_more"),
        ("lnschema_core", "0010_dataset_categories_file_categories"),
        ("lnschema_core", "0011_label_remove_tag_created_by_remove_tag_parents_and_more"),
        ("lnschema_core", "0012_remove_label_ref_id_remove_label_ref_orm_and_more"),
        ("lnschema_core", "0013_remove_feature_labels_orm_and_more"),
        ("lnschema_core", "0014_rename_ref_field_featureset_registry"),
        ("lnschema_core", "0015_file_initial_version_file_version"),
        ("lnschema_core", "0016_dataset_input_of_dataset_run_dataset_transform_and_more"),
        ("lnschema_core", "0017_dataset_initial_version_dataset_version"),
        ("lnschema_core", "0018_rename_datasetlabel_datasetulabel_and_more"),
        ("lnschema_core", "0019_dataset_reference_dataset_reference_type_and_more"),
        ("lnschema_core", "0020_run_report_transform_latest_report_and_more"),
        ("lnschema_core", "0021_dataset_storage_alter_dataset_file"),
        ("lnschema_core", "0022_migrate_to_integer_pks"),
        ("lnschema_core", "0023_export_legacy_data"),
    ]

    dependencies = []  # type: ignore

    operations = [
        migrations.CreateModel(
            name="Dataset",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=lnschema_core.ids.base62_20, max_length=20, unique=True)),
                ("name", models.CharField(db_index=True, default=None, max_length=255)),
                ("description", models.TextField(default=None, null=True)),
                ("version", models.CharField(db_index=True, default=None, max_length=10, null=True)),
                ("hash", models.CharField(db_index=True, default=None, max_length=86, null=True)),
                ("reference", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("reference_type", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
            ],
            options={
                "abstract": False,
            },
            bases=(models.Model, lnschema_core.models.Data),
        ),
        migrations.CreateModel(
            name="Feature",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=lnschema_core.ids.base62_12, max_length=12, unique=True)),
                ("name", models.CharField(db_index=True, default=None, max_length=255)),
                ("type", models.CharField(db_index=True, default=None, max_length=64)),
                ("unit", models.CharField(db_index=True, default=None, max_length=30, null=True)),
                ("description", models.TextField(db_index=True, default=None, null=True)),
                ("registries", models.CharField(db_index=True, default=None, max_length=128, null=True)),
                ("synonyms", models.TextField(default=None, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
            ],
            options={
                "abstract": False,
            },
            bases=(models.Model, lnschema_core.models.CanValidate),
        ),
        migrations.CreateModel(
            name="FeatureSet",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=None, max_length=20, unique=True)),
                ("name", models.CharField(default=None, max_length=128, null=True)),
                ("n", models.IntegerField()),
                ("type", models.CharField(default=None, max_length=64, null=True)),
                ("registry", models.CharField(db_index=True, max_length=128)),
                ("hash", models.CharField(db_index=True, default=None, max_length=20, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="File",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, max_length=20, unique=True)),
                ("key", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("suffix", models.CharField(db_index=True, default=None, max_length=30)),
                ("accessor", models.CharField(db_index=True, default=None, max_length=64, null=True)),
                ("description", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("version", models.CharField(db_index=True, default=None, max_length=10, null=True)),
                ("size", models.BigIntegerField(db_index=True, null=True)),
                ("hash", models.CharField(db_index=True, default=None, max_length=86, null=True)),
                ("hash_type", models.CharField(db_index=True, default=None, max_length=30, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
            ],
            bases=(models.Model, lnschema_core.models.Data),
        ),
        migrations.CreateModel(
            name="User",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=None, max_length=8, unique=True)),
                ("handle", models.CharField(db_index=True, default=None, max_length=30, unique=True)),
                ("email", models.CharField(db_index=True, default=None, max_length=255, unique=True)),
                ("name", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
            ],
            options={
                "abstract": False,
            },
            bases=(models.Model, lnschema_core.models.CanValidate),
        ),
        migrations.CreateModel(
            name="ULabel",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=lnschema_core.ids.base62_8, max_length=8, unique=True)),
                ("name", models.CharField(db_index=True, default=None, max_length=255, unique=True)),
                ("description", models.TextField(default=None, null=True)),
                ("reference", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("reference_type", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_ulabels", to="lnschema_core.user"
                    ),
                ),
                ("parents", models.ManyToManyField(related_name="children", to="lnschema_core.ulabel")),
            ],
            options={
                "abstract": False,
            },
            bases=(models.Model, lnschema_core.models.HasParents, lnschema_core.models.CanValidate),
        ),
        migrations.CreateModel(
            name="Transform",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=None, max_length=14, unique=True)),
                ("name", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("short_name", models.CharField(db_index=True, default=None, max_length=128, null=True)),
                ("version", models.CharField(db_index=True, default=None, max_length=10, null=True)),
                (
                    "type",
                    models.CharField(
                        choices=[("pipeline", "pipeline"), ("notebook", "notebook"), ("app", "app"), ("api", "api")],
                        db_index=True,
                        default=lnschema_core.types.TransformType["pipeline"],
                        max_length=20,
                    ),
                ),
                ("reference", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("reference_type", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_transforms", to="lnschema_core.user"
                    ),
                ),
                ("initial_version", models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to="lnschema_core.transform")),
                (
                    "latest_report",
                    models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="latest_report_of", to="lnschema_core.file"),
                ),
                ("parents", models.ManyToManyField(related_name="children", to="lnschema_core.transform")),
                ("source_file", models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="source_of", to="lnschema_core.file")),
            ],
            options={
                "abstract": False,
            },
            bases=(models.Model, lnschema_core.models.HasParents),
        ),
        migrations.CreateModel(
            name="Storage",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=lnschema_core.ids.base62_8, max_length=8, unique=True)),
                ("root", models.CharField(db_index=True, default=None, max_length=255, unique=True)),
                ("type", models.CharField(db_index=True, max_length=30)),
                ("region", models.CharField(db_index=True, default=None, max_length=64, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_storages", to="lnschema_core.user"
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Run",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=lnschema_core.ids.base62_20, max_length=20, unique=True)),
                ("run_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("is_consecutive", models.BooleanField(default=None, null=True)),
                ("reference", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("reference_type", models.CharField(db_index=True, default=None, max_length=255, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.CASCADE, related_name="created_runs", to="lnschema_core.user"
                    ),
                ),
                ("report", models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="report_of", to="lnschema_core.file")),
                ("transform", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="runs", to="lnschema_core.transform")),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Modality",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                ("uid", models.CharField(db_index=True, default=lnschema_core.ids.base62_8, max_length=8, unique=True)),
                ("name", models.CharField(db_index=True, max_length=256)),
                ("ontology_id", models.CharField(db_index=True, default=None, max_length=32, null=True)),
                ("abbr", models.CharField(db_index=True, default=None, max_length=32, null=True, unique=True)),
                ("synonyms", models.TextField(default=None, null=True)),
                ("description", models.TextField(default=None, null=True)),
                ("molecule", models.TextField(db_index=True, default=None, null=True)),
                ("instrument", models.TextField(db_index=True, default=None, null=True)),
                ("measurement", models.TextField(db_index=True, default=None, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True, db_index=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_modalities", to="lnschema_core.user"
                    ),
                ),
                ("parents", models.ManyToManyField(related_name="children", to="lnschema_core.modality")),
            ],
            options={
                "abstract": False,
            },
            bases=(models.Model, lnschema_core.models.HasParents, lnschema_core.models.CanValidate),
        ),
        migrations.CreateModel(
            name="FileULabel",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                ("feature", models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.feature")),
                ("file", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.file")),
                ("ulabel", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.ulabel")),
            ],
            options={
                "unique_together": {("file", "ulabel")},
            },
            bases=(models.Model, lnschema_core.models.LinkORM),
        ),
        migrations.CreateModel(
            name="FileFeatureSet",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                ("slot", models.CharField(default=None, max_length=40, null=True)),
                ("feature_set", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.featureset")),
                ("file", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.file")),
            ],
            options={
                "unique_together": {("file", "feature_set")},
            },
            bases=(models.Model, lnschema_core.models.LinkORM),
        ),
        migrations.AddField(
            model_name="file",
            name="created_by",
            field=models.ForeignKey(
                default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_files", to="lnschema_core.user"
            ),
        ),
        migrations.AddField(
            model_name="file",
            name="feature_sets",
            field=models.ManyToManyField(related_name="files", through="lnschema_core.FileFeatureSet", to="lnschema_core.featureset"),
        ),
        migrations.AddField(
            model_name="file",
            name="initial_version",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to="lnschema_core.file"),
        ),
        migrations.AddField(
            model_name="file",
            name="input_of",
            field=models.ManyToManyField(related_name="input_files", to="lnschema_core.run"),
        ),
        migrations.AddField(
            model_name="file",
            name="run",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="output_files", to="lnschema_core.run"),
        ),
        migrations.AddField(
            model_name="file",
            name="storage",
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name="files", to="lnschema_core.storage"),
        ),
        migrations.AddField(
            model_name="file",
            name="transform",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="output_files", to="lnschema_core.transform"),
        ),
        migrations.AddField(
            model_name="file",
            name="ulabels",
            field=models.ManyToManyField(related_name="files", through="lnschema_core.FileULabel", to="lnschema_core.ulabel"),
        ),
        migrations.AddField(
            model_name="featureset",
            name="created_by",
            field=models.ForeignKey(
                default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_feature_sets", to="lnschema_core.user"
            ),
        ),
        migrations.AddField(
            model_name="featureset",
            name="modality",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="feature_sets", to="lnschema_core.modality"),
        ),
        migrations.AddField(
            model_name="feature",
            name="created_by",
            field=models.ForeignKey(
                default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_features", to="lnschema_core.user"
            ),
        ),
        migrations.AddField(
            model_name="feature",
            name="feature_sets",
            field=models.ManyToManyField(related_name="features", to="lnschema_core.featureset"),
        ),
        migrations.AddField(
            model_name="feature",
            name="modality",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="features", to="lnschema_core.modality"),
        ),
        migrations.CreateModel(
            name="DatasetULabel",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                ("dataset", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.dataset")),
                ("feature", models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.feature")),
                ("ulabel", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.ulabel")),
            ],
            options={
                "unique_together": {("dataset", "ulabel")},
            },
            bases=(models.Model, lnschema_core.models.LinkORM),
        ),
        migrations.CreateModel(
            name="DatasetFeatureSet",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                ("slot", models.CharField(default=None, max_length=50, null=True)),
                ("dataset", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.dataset")),
                ("feature_set", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.featureset")),
            ],
            options={
                "unique_together": {("dataset", "feature_set")},
            },
            bases=(models.Model, lnschema_core.models.LinkORM),
        ),
        migrations.AddField(
            model_name="dataset",
            name="created_by",
            field=models.ForeignKey(
                default=lnschema_core.users.current_user_id, on_delete=django.db.models.deletion.PROTECT, related_name="created_datasets", to="lnschema_core.user"
            ),
        ),
        migrations.AddField(
            model_name="dataset",
            name="feature_sets",
            field=models.ManyToManyField(related_name="datasets", through="lnschema_core.DatasetFeatureSet", to="lnschema_core.featureset"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="file",
            field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, related_name="dataset", to="lnschema_core.file"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="files",
            field=models.ManyToManyField(related_name="datasets", to="lnschema_core.file"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="initial_version",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to="lnschema_core.dataset"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="input_of",
            field=models.ManyToManyField(related_name="input_datasets", to="lnschema_core.run"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="run",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="output_datasets", to="lnschema_core.run"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="storage",
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name="datasets", to="lnschema_core.storage"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="transform",
            field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="output_datasets", to="lnschema_core.transform"),
        ),
        migrations.AddField(
            model_name="dataset",
            name="ulabels",
            field=models.ManyToManyField(related_name="datasets", through="lnschema_core.DatasetULabel", to="lnschema_core.ulabel"),
        ),
        migrations.AlterUniqueTogether(
            name="file",
            unique_together={("storage", "key")},
        ),
    ]
