# Generated by Django 4.2.2 on 2023-07-28 13:22

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


class Migration(migrations.Migration):
    dependencies = [
        ("lnschema_core", "0012_remove_label_ref_id_remove_label_ref_orm_and_more"),
    ]

    operations = [
        migrations.RemoveField(
            model_name="feature",
            name="labels_orm",
        ),
        migrations.RemoveField(
            model_name="feature",
            name="labels_schema",
        ),
        migrations.AddField(
            model_name="feature",
            name="registries",
            field=models.CharField(db_index=True, default=None, max_length=128, null=True),
        ),
        migrations.AlterUniqueTogether(
            name="label",
            unique_together=set(),
        ),
        migrations.CreateModel(
            name="FileLabel",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("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")),
                ("label", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="lnschema_core.label")),
            ],
            options={
                "unique_together": {("file", "label")},
            },
        ),
        migrations.RunSQL("CREATE TABLE lnschema_core_filelabel_tmp (id BIGINT, file_id TEXT, label_id TEXT)"),
        migrations.RunSQL("INSERT INTO lnschema_core_filelabel_tmp (id, file_id, label_id) SELECT id, file_id, label_id from lnschema_core_file_labels"),
        migrations.RemoveField(
            model_name="file",
            name="labels",
        ),
        migrations.AddField(
            model_name="file",
            name="labels",
            field=models.ManyToManyField(related_name="files", through="lnschema_core.FileLabel", to="lnschema_core.label"),
        ),
        migrations.RunSQL("INSERT INTO lnschema_core_filelabel (id, file_id, label_id) SELECT id, file_id, label_id from lnschema_core_filelabel_tmp"),
        migrations.RunSQL("DROP TABLE lnschema_core_filelabel_tmp"),
        migrations.RemoveField(
            model_name="label",
            name="feature",
        ),
        migrations.RemoveField(
            model_name="featureset",
            name="ref_field",
        ),
        migrations.RenameField(
            model_name="featureset",
            old_name="ref_orm",
            new_name="ref_field",
        ),
        migrations.RemoveField(
            model_name="featureset",
            name="ref_schema",
        ),
        migrations.AlterField(
            model_name="featureset",
            name="ref_field",
            field=models.CharField(db_index=True, max_length=128),
        ),
    ]
