From 661fa725d56ef652f1a7c5cd4fad8f5b823bd1c3 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Wed, 20 Nov 2024 16:20:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0023_rename_publicsource_encode_uid.py | 1141 +++++++++++++++++ ...24_remove_cellline_collections_and_more.py | 64 + ...lline_alter_cellline_artifacts_and_more.py | 829 ++++++++++++ ...cellline_cell_line_ref_is_name_and_more.py | 520 ++++++++ ...ve_artifactcellline_created_at_and_more.py | 388 ++++++ ...28_artifactcellline_created_at_and_more.py | 703 ++++++++++ bionty/migrations/0028_squashed.py | 9 +- ...tifactgene_feature_ref_is_name_and_more.py | 48 +- 8 files changed, 3700 insertions(+), 2 deletions(-) create mode 100644 bionty/migrations/0023_rename_publicsource_encode_uid.py create mode 100644 bionty/migrations/0024_remove_cellline_collections_and_more.py create mode 100644 bionty/migrations/0025_artifactcellline_alter_cellline_artifacts_and_more.py create mode 100644 bionty/migrations/0026_artifactcellline_cell_line_ref_is_name_and_more.py create mode 100644 bionty/migrations/0027_remove_artifactcellline_created_at_and_more.py create mode 100644 bionty/migrations/0028_artifactcellline_created_at_and_more.py diff --git a/bionty/migrations/0023_rename_publicsource_encode_uid.py b/bionty/migrations/0023_rename_publicsource_encode_uid.py new file mode 100644 index 0000000..76097eb --- /dev/null +++ b/bionty/migrations/0023_rename_publicsource_encode_uid.py @@ -0,0 +1,1141 @@ +# Generated by Django 5.0.6 on 2024-05-16 15:59 + +import django.db.models.deletion +import lnschema_core.models +import lnschema_core.users +from django.db import migrations, models + +import bionty.ids + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + ("lnschema_core", "0037_rename_dataset_to_collection"), + ] + + operations = [ + migrations.CreateModel( + name="Organism", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, max_length=8, unique=True + ), + ), + ( + "name", + models.CharField( + db_index=True, default=None, max_length=64, unique=True + ), + ), + ( + "ontology_id", + models.CharField( + db_index=True, + default=None, + max_length=32, + null=True, + unique=True, + ), + ), + ( + "scientific_name", + models.CharField( + db_index=True, + default=None, + max_length=64, + null=True, + unique=True, + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="organism", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="organism", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_organism", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.organism" + ), + ), + ], + options={ + "abstract": False, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="PublicSource", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.publicsource, + max_length=8, + unique=True, + ), + ), + ("entity", models.CharField(db_index=True, max_length=64)), + ("organism", models.CharField(db_index=True, max_length=64)), + ("currently_used", models.BooleanField(db_index=True, default=False)), + ("source", models.CharField(db_index=True, max_length=64)), + ("source_name", models.TextField(blank=True, db_index=True)), + ("version", models.CharField(db_index=True, max_length=64)), + ("url", models.TextField(default=None, null=True)), + ("md5", models.TextField(default=None, null=True)), + ("source_website", 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)), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_public_sources", + to="lnschema_core.user", + ), + ), + ], + options={ + "unique_together": {("entity", "source", "organism", "version")}, + }, + ), + migrations.CreateModel( + name="Protein", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.protein, max_length=12, unique=True + ), + ), + ( + "name", + models.CharField( + db_index=True, default=None, max_length=64, null=True + ), + ), + ( + "uniprotkb_id", + models.CharField( + db_index=True, + default=None, + max_length=10, + null=True, + unique=True, + ), + ), + ("synonyms", models.TextField(default=None, null=True)), + ("length", models.BigIntegerField(db_index=True, null=True)), + ( + "gene_symbol", + models.CharField( + db_index=True, default=None, max_length=64, null=True + ), + ), + ("ensembl_gene_ids", 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)), + ( + "artifacts", + models.ManyToManyField( + related_name="proteins", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="proteins", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_proteins", + to="lnschema_core.user", + ), + ), + ( + "feature_sets", + models.ManyToManyField( + related_name="proteins", to="lnschema_core.featureset" + ), + ), + ( + "organism", + models.ForeignKey( + default=None, + on_delete=django.db.models.deletion.PROTECT, + related_name="proteins", + to="bionty.organism", + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="proteins", + to="bionty.publicsource", + ), + ), + ], + options={ + "abstract": False, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.AddField( + model_name="organism", + name="public_source", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="organisms", + to="bionty.publicsource", + ), + ), + migrations.CreateModel( + name="Gene", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.gene, max_length=12, unique=True + ), + ), + ( + "symbol", + models.CharField( + db_index=True, default=None, max_length=64, null=True + ), + ), + ( + "stable_id", + models.CharField( + db_index=True, + default=None, + max_length=64, + null=True, + unique=True, + ), + ), + ( + "ensembl_gene_id", + models.CharField( + db_index=True, + default=None, + max_length=64, + null=True, + unique=True, + ), + ), + ("ncbi_gene_ids", models.TextField(default=None, null=True)), + ( + "biotype", + models.CharField( + db_index=True, default=None, max_length=64, null=True + ), + ), + ("description", models.TextField(default=None, 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)), + ( + "artifacts", + models.ManyToManyField( + related_name="genes", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="genes", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_genes", + to="lnschema_core.user", + ), + ), + ( + "feature_sets", + models.ManyToManyField( + related_name="genes", to="lnschema_core.featureset" + ), + ), + ( + "organism", + models.ForeignKey( + default=None, + on_delete=django.db.models.deletion.PROTECT, + related_name="genes", + to="bionty.organism", + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="genes", + to="bionty.publicsource", + ), + ), + ], + options={ + "abstract": False, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="CellMarker", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.cellmarker, + max_length=12, + unique=True, + ), + ), + ( + "name", + models.CharField( + db_index=True, default=None, max_length=64, unique=True + ), + ), + ("synonyms", models.TextField(default=None, null=True)), + ( + "gene_symbol", + models.CharField( + db_index=True, default=None, max_length=64, null=True + ), + ), + ( + "ncbi_gene_id", + models.CharField( + db_index=True, default=None, max_length=32, null=True + ), + ), + ( + "uniprotkb_id", + models.CharField( + db_index=True, default=None, max_length=10, null=True + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="cell_markers", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="cell_markers", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_cell_markers", + to="lnschema_core.user", + ), + ), + ( + "feature_sets", + models.ManyToManyField( + related_name="cell_markers", to="lnschema_core.featureset" + ), + ), + ( + "organism", + models.ForeignKey( + default=None, + on_delete=django.db.models.deletion.PROTECT, + related_name="cell_markers", + to="bionty.organism", + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="cell_markers", + to="bionty.publicsource", + ), + ), + ], + options={ + "abstract": False, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="Phenotype", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="phenotypes", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="phenotypes", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_phenotypes", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.phenotype" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="phenotypes", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="Pathway", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="pathways", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="pathways", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_pathways", + to="lnschema_core.user", + ), + ), + ( + "feature_sets", + models.ManyToManyField( + related_name="pathways", to="lnschema_core.featureset" + ), + ), + ( + "genes", + models.ManyToManyField(related_name="pathways", to="bionty.gene"), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.pathway" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="pathways", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="ExperimentalFactor", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ( + "artifacts", + models.ManyToManyField( + related_name="experimental_factors", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="experimental_factors", + to="lnschema_core.collection", + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_experimental_factors", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.experimentalfactor" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="experimental_factors", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="Ethnicity", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="ethnicities", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="ethnicities", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_ethnicities", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.ethnicity" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="ethnicities", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="Disease", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="diseases", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="diseases", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_diseases", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.disease" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="diseases", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="DevelopmentalStage", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="developmental_stages", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="developmental_stages", + to="lnschema_core.collection", + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_developmental_stages", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.developmentalstage" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="developmental_stages", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="CellType", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="cell_types", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="cell_types", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_cell_types", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.celltype" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="cell_types", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="CellLine", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="cell_lines", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="cell_lines", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_cell_lines", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField( + related_name="children", to="bionty.cellline" + ), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="cell_lines", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + migrations.CreateModel( + name="Tissue", + fields=[ + ("id", models.AutoField(primary_key=True, serialize=False)), + ( + "uid", + models.CharField( + default=bionty.ids.ontology, 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)), + ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)), + ("updated_at", models.DateTimeField(auto_now=True, db_index=True)), + ( + "artifacts", + models.ManyToManyField( + related_name="tissues", to="lnschema_core.artifact" + ), + ), + ( + "collections", + models.ManyToManyField( + related_name="tissues", to="lnschema_core.collection" + ), + ), + ( + "created_by", + models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + related_name="created_tissues", + to="lnschema_core.user", + ), + ), + ( + "parents", + models.ManyToManyField(related_name="children", to="bionty.tissue"), + ), + ( + "public_source", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="tissues", + to="bionty.publicsource", + ), + ), + ], + options={ + "unique_together": {("name", "ontology_id")}, + }, + bases=( + models.Model, + lnschema_core.models.HasParents, + lnschema_core.models.CanCurate, + ), + ), + ] diff --git a/bionty/migrations/0024_remove_cellline_collections_and_more.py b/bionty/migrations/0024_remove_cellline_collections_and_more.py new file mode 100644 index 0000000..f4fc1a6 --- /dev/null +++ b/bionty/migrations/0024_remove_cellline_collections_and_more.py @@ -0,0 +1,64 @@ +# Generated by Django 5.0.6 on 2024-05-15 16:19 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("bionty", "0023_rename_publicsource_encode_uid"), + ] + + operations = [ + migrations.RemoveField( + model_name="cellline", + name="collections", + ), + migrations.RemoveField( + model_name="cellmarker", + name="collections", + ), + migrations.RemoveField( + model_name="celltype", + name="collections", + ), + migrations.RemoveField( + model_name="developmentalstage", + name="collections", + ), + migrations.RemoveField( + model_name="disease", + name="collections", + ), + migrations.RemoveField( + model_name="ethnicity", + name="collections", + ), + migrations.RemoveField( + model_name="experimentalfactor", + name="collections", + ), + migrations.RemoveField( + model_name="gene", + name="collections", + ), + migrations.RemoveField( + model_name="organism", + name="collections", + ), + migrations.RemoveField( + model_name="pathway", + name="collections", + ), + migrations.RemoveField( + model_name="phenotype", + name="collections", + ), + migrations.RemoveField( + model_name="protein", + name="collections", + ), + migrations.RemoveField( + model_name="tissue", + name="collections", + ), + ] diff --git a/bionty/migrations/0025_artifactcellline_alter_cellline_artifacts_and_more.py b/bionty/migrations/0025_artifactcellline_alter_cellline_artifacts_and_more.py new file mode 100644 index 0000000..a929a89 --- /dev/null +++ b/bionty/migrations/0025_artifactcellline_alter_cellline_artifacts_and_more.py @@ -0,0 +1,829 @@ +# Generated by Django 5.0.6 on 2024-05-16 06:06 + +import django.db.models.deletion +import lnschema_core.models +import lnschema_core.users +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("bionty", "0024_remove_cellline_collections_and_more"), + ] + + operations = [ + migrations.CreateModel( + name="ArtifactOrganism", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "organism", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Organism"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactGene", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "gene", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Gene"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactProtein", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "protein", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Protein"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactCellMarker", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "cell_marker", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.CellMarker"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactTissue", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "tissue", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Tissue"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactCellType", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "cell_type", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.CellType"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactDisease", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "disease", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Disease"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactCellLine", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "cell_line", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.CellLine"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactPhenotype", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "phenotype", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Phenotype"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactPathway", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "pathway", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Pathway"), + ), + ], + ), + migrations.CreateModel( + name="ArtifactExperimentalFactor", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "experimental_factor", + models.ForeignKey( + on_delete=models.CASCADE, + to="bionty.ExperimentalFactor", + ), + ), + ], + ), + migrations.CreateModel( + name="ArtifactDevelopmentalStage", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "developmental_stage", + models.ForeignKey( + on_delete=models.CASCADE, + to="bionty.DevelopmentalStage", + ), + ), + ], + ), + migrations.CreateModel( + name="ArtifactEthnicity", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "feature", + models.ForeignKey( + on_delete=models.PROTECT, + null=True, + default=None, + to="lnschema_core.Feature", + ), + ), + ( + "created_by", + models.ForeignKey( + on_delete=models.PROTECT, + default=lnschema_core.users.current_user_id, + to="lnschema_core.User", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "artifact", + models.ForeignKey( + on_delete=models.CASCADE, to="lnschema_core.Artifact" + ), + ), + ( + "ethnicity", + models.ForeignKey(on_delete=models.CASCADE, to="bionty.Ethnicity"), + ), + ], + ), + # Insert data into the new through models + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactorganism (artifact_id, organism_id, feature_id, created_by_id, created_at) + SELECT artifact_id, organism_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_organism_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactgene (artifact_id, gene_id, feature_id, created_by_id, created_at) + SELECT artifact_id, gene_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_gene_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactprotein (artifact_id, protein_id, feature_id, created_by_id, created_at) + SELECT artifact_id, protein_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_protein_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactcellmarker (artifact_id, cell_marker_id, feature_id, created_by_id, created_at) + SELECT artifact_id, cellmarker_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_cellmarker_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifacttissue (artifact_id, tissue_id, feature_id, created_by_id, created_at) + SELECT artifact_id, tissue_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_tissue_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactcelltype (artifact_id, cell_type_id, feature_id, created_by_id, created_at) + SELECT artifact_id, celltype_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_celltype_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactdisease (artifact_id, disease_id, feature_id, created_by_id, created_at) + SELECT artifact_id, disease_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_disease_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactcellline (artifact_id, cell_line_id, feature_id, created_by_id, created_at) + SELECT artifact_id, cellline_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_cellline_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactphenotype (artifact_id, phenotype_id, feature_id, created_by_id, created_at) + SELECT artifact_id, phenotype_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_phenotype_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactpathway (artifact_id, pathway_id, feature_id, created_by_id, created_at) + SELECT artifact_id, pathway_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_pathway_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactexperimentalfactor (artifact_id, experimental_factor_id, feature_id, created_by_id, created_at) + SELECT artifact_id, experimentalfactor_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_experimentalfactor_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactdevelopmentalstage (artifact_id, developmental_stage_id, feature_id, created_by_id, created_at) + SELECT artifact_id, developmentalstage_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_developmentalstage_artifacts; + """ # Replace with appropriate user_id logic + ), + migrations.RunSQL( + f""" + INSERT INTO bionty_artifactethnicity (artifact_id, ethnicity_id, feature_id, created_by_id, created_at) + SELECT artifact_id, ethnicity_id, NULL, {1}, CURRENT_TIMESTAMP + FROM bionty_ethnicity_artifacts; + """ # Replace with appropriate user_id logic + ), + # Remove the old ManyToMany fields and replace them with the new through models + migrations.RemoveField( + model_name="organism", + name="artifacts", + ), + migrations.AddField( + model_name="organism", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactOrganism", + to="lnschema_core.Artifact", + related_name="organisms", + ), + ), + migrations.RemoveField( + model_name="gene", + name="artifacts", + ), + migrations.AddField( + model_name="gene", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactGene", + to="lnschema_core.Artifact", + related_name="genes", + ), + ), + migrations.RemoveField( + model_name="protein", + name="artifacts", + ), + migrations.AddField( + model_name="protein", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactProtein", + to="lnschema_core.Artifact", + related_name="proteins", + ), + ), + migrations.RemoveField( + model_name="cellmarker", + name="artifacts", + ), + migrations.AddField( + model_name="cellmarker", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactCellMarker", + to="lnschema_core.Artifact", + related_name="cell_markers", + ), + ), + migrations.RemoveField( + model_name="tissue", + name="artifacts", + ), + migrations.AddField( + model_name="tissue", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactTissue", + to="lnschema_core.Artifact", + related_name="tissues", + ), + ), + migrations.RemoveField( + model_name="celltype", + name="artifacts", + ), + migrations.AddField( + model_name="celltype", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactCellType", + to="lnschema_core.Artifact", + related_name="cell_types", + ), + ), + migrations.RemoveField( + model_name="disease", + name="artifacts", + ), + migrations.AddField( + model_name="disease", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactDisease", + to="lnschema_core.Artifact", + related_name="diseases", + ), + ), + migrations.RemoveField( + model_name="cellline", + name="artifacts", + ), + migrations.AddField( + model_name="cellline", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactCellLine", + to="lnschema_core.Artifact", + related_name="cell_lines", + ), + ), + migrations.RemoveField( + model_name="phenotype", + name="artifacts", + ), + migrations.AddField( + model_name="phenotype", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactPhenotype", + to="lnschema_core.Artifact", + related_name="phenotypes", + ), + ), + migrations.RemoveField( + model_name="pathway", + name="artifacts", + ), + migrations.AddField( + model_name="pathway", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactPathway", + to="lnschema_core.Artifact", + related_name="pathways", + ), + ), + migrations.RemoveField( + model_name="experimentalfactor", + name="artifacts", + ), + migrations.AddField( + model_name="experimentalfactor", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactExperimentalFactor", + to="lnschema_core.Artifact", + related_name="experimental_factors", + ), + ), + migrations.RemoveField( + model_name="developmentalstage", + name="artifacts", + ), + migrations.AddField( + model_name="developmentalstage", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactDevelopmentalStage", + to="lnschema_core.Artifact", + related_name="developmental_stages", + ), + ), + migrations.RemoveField( + model_name="ethnicity", + name="artifacts", + ), + migrations.AddField( + model_name="ethnicity", + name="artifacts", + field=models.ManyToManyField( + through="bionty.ArtifactEthnicity", + to="lnschema_core.Artifact", + related_name="ethnicities", + ), + ), + ] diff --git a/bionty/migrations/0026_artifactcellline_cell_line_ref_is_name_and_more.py b/bionty/migrations/0026_artifactcellline_cell_line_ref_is_name_and_more.py new file mode 100644 index 0000000..2165eca --- /dev/null +++ b/bionty/migrations/0026_artifactcellline_cell_line_ref_is_name_and_more.py @@ -0,0 +1,520 @@ +# Generated by Django 5.0.6 on 2024-05-18 14:14 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("bionty", "0025_artifactcellline_alter_cellline_artifacts_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="artifactcellline", + name="cell_line_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactcellline", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactcellmarker", + name="cell_marker_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactcellmarker", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactcelltype", + name="cell_type_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactcelltype", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactdevelopmentalstage", + name="developmental_stage_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactdevelopmentalstage", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactdisease", + name="disease_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactdisease", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactethnicity", + name="ethnicity_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactethnicity", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactexperimentalfactor", + name="experimental_factor_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactexperimentalfactor", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactgene", + name="feature_ref_is_symbol", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactgene", + name="gene_ref_is_symbol", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactorganism", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactorganism", + name="organism_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactpathway", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactpathway", + name="pathway_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactphenotype", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactphenotype", + name="phenotype_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactprotein", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifactprotein", + name="protein_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifacttissue", + name="feature_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AddField( + model_name="artifacttissue", + name="tissue_ref_is_name", + field=models.BooleanField(default=None, null=True), + ), + migrations.AlterField( + model_name="artifactcellline", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="cell_line_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactcellline", + name="cell_line", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.cellline", + ), + ), + migrations.AlterField( + model_name="artifactcellline", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactcellline_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactcellmarker", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="cell_marker_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactcellmarker", + name="cell_marker", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.cellmarker", + ), + ), + migrations.AlterField( + model_name="artifactcellmarker", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactcellmarker_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactcelltype", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="cell_type_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactcelltype", + name="cell_type", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.celltype", + ), + ), + migrations.AlterField( + model_name="artifactcelltype", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactcelltype_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactdevelopmentalstage", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="developmental_stage_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactdevelopmentalstage", + name="developmental_stage", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.developmentalstage", + ), + ), + migrations.AlterField( + model_name="artifactdevelopmentalstage", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactdevelopmentalstage_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactdisease", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="disease_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactdisease", + name="disease", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.disease", + ), + ), + migrations.AlterField( + model_name="artifactdisease", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactdisease_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactethnicity", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="ethnicity_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactethnicity", + name="ethnicity", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.ethnicity", + ), + ), + migrations.AlterField( + model_name="artifactethnicity", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactethnicity_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactexperimentalfactor", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="experimental_factor_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactexperimentalfactor", + name="experimental_factor", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.experimentalfactor", + ), + ), + migrations.AlterField( + model_name="artifactexperimentalfactor", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactexperimentalfactor_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactgene", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="gene_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactgene", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactgene_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactgene", + name="gene", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.gene", + ), + ), + migrations.AlterField( + model_name="artifactorganism", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="organism_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactorganism", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactorganism_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactorganism", + name="organism", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.organism", + ), + ), + migrations.AlterField( + model_name="artifactpathway", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="pathway_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactpathway", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactpathway_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactpathway", + name="pathway", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.pathway", + ), + ), + migrations.AlterField( + model_name="artifactphenotype", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="phenotype_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactphenotype", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactphenotype_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactphenotype", + name="phenotype", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.phenotype", + ), + ), + migrations.AlterField( + model_name="artifactprotein", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="protein_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactprotein", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifactprotein_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifactprotein", + name="protein", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.protein", + ), + ), + migrations.AlterField( + model_name="artifacttissue", + name="artifact", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="tissue_links", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifacttissue", + name="feature", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="artifacttissue_links", + to="lnschema_core.feature", + ), + ), + migrations.AlterField( + model_name="artifacttissue", + name="tissue", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="artifact_links", + to="bionty.tissue", + ), + ), + ] diff --git a/bionty/migrations/0027_remove_artifactcellline_created_at_and_more.py b/bionty/migrations/0027_remove_artifactcellline_created_at_and_more.py new file mode 100644 index 0000000..cdc0d8e --- /dev/null +++ b/bionty/migrations/0027_remove_artifactcellline_created_at_and_more.py @@ -0,0 +1,388 @@ +# Generated by Django 5.0.6 on 2024-05-18 21:18 + +import django.db.models.deletion +import lnschema_core.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("bionty", "0026_artifactcellline_cell_line_ref_is_name_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="artifactcellline", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactcellline", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactcellmarker", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactcellmarker", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactcelltype", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactcelltype", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactdevelopmentalstage", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactdevelopmentalstage", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactdisease", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactdisease", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactethnicity", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactethnicity", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactexperimentalfactor", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactexperimentalfactor", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactgene", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactgene", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactorganism", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactorganism", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactpathway", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactpathway", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactphenotype", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactphenotype", + name="created_by", + ), + migrations.RemoveField( + model_name="artifactprotein", + name="created_at", + ), + migrations.RemoveField( + model_name="artifactprotein", + name="created_by", + ), + migrations.RemoveField( + model_name="artifacttissue", + name="created_at", + ), + migrations.RemoveField( + model_name="artifacttissue", + name="created_by", + ), + migrations.AlterField( + model_name="artifactcellline", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactcellmarker", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactcelltype", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactdevelopmentalstage", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactdisease", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactethnicity", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactexperimentalfactor", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactgene", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactorganism", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactpathway", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactphenotype", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifactprotein", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name="artifacttissue", + name="id", + field=models.BigAutoField(primary_key=True, serialize=False), + ), + migrations.CreateModel( + name="FeatureSetCellMarker", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ( + "cellmarker", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="bionty.cellmarker", + ), + ), + ( + "featureset", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="lnschema_core.featureset", + ), + ), + ], + options={ + "abstract": False, + }, + bases=(models.Model, lnschema_core.models.LinkORM), + ), + migrations.CreateModel( + name="FeatureSetGene", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ( + "featureset", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="lnschema_core.featureset", + ), + ), + ( + "gene", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="bionty.gene", + ), + ), + ], + options={ + "abstract": False, + }, + bases=(models.Model, lnschema_core.models.LinkORM), + ), + migrations.CreateModel( + name="FeatureSetPathway", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ( + "featureset", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="lnschema_core.featureset", + ), + ), + ( + "pathway", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="bionty.pathway", + ), + ), + ], + options={ + "abstract": False, + }, + bases=(models.Model, lnschema_core.models.LinkORM), + ), + migrations.CreateModel( + name="FeatureSetProtein", + fields=[ + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ( + "featureset", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="lnschema_core.featureset", + ), + ), + ( + "protein", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="bionty.protein", + ), + ), + ], + options={ + "abstract": False, + }, + bases=(models.Model, lnschema_core.models.LinkORM), + ), + migrations.RunSQL( + """ + INSERT INTO bionty_featuresetgene (featureset_id, gene_id) + SELECT featureset_id, gene_id + FROM bionty_gene_feature_sets; + """ + ), + migrations.RunSQL( + """ + INSERT INTO bionty_featuresetprotein (featureset_id, protein_id) + SELECT featureset_id, protein_id + FROM bionty_protein_feature_sets; + """ + ), + migrations.RunSQL( + """ + INSERT INTO bionty_featuresetcellmarker (featureset_id, cellmarker_id) + SELECT featureset_id, cellmarker_id + FROM bionty_cellmarker_feature_sets; + """ + ), + migrations.RunSQL( + """ + INSERT INTO bionty_featuresetpathway (featureset_id, pathway_id) + SELECT featureset_id, pathway_id + FROM bionty_pathway_feature_sets; + """ + ), + # Remove the old ManyToMany fields and replace them with the new through models + migrations.RemoveField( + model_name="gene", + name="feature_sets", + ), + migrations.AddField( + model_name="gene", + name="feature_sets", + field=models.ManyToManyField( + through="bionty.FeatureSetGene", + to="lnschema_core.FeatureSet", + related_name="genes", + ), + ), + migrations.RemoveField( + model_name="protein", + name="feature_sets", + ), + migrations.AddField( + model_name="protein", + name="feature_sets", + field=models.ManyToManyField( + through="bionty.FeatureSetProtein", + to="lnschema_core.FeatureSet", + related_name="proteins", + ), + ), + migrations.RemoveField( + model_name="cellmarker", + name="feature_sets", + ), + migrations.AddField( + model_name="cellmarker", + name="feature_sets", + field=models.ManyToManyField( + through="bionty.FeatureSetCellMarker", + to="lnschema_core.FeatureSet", + related_name="cell_markers", + ), + ), + migrations.RemoveField( + model_name="pathway", + name="feature_sets", + ), + migrations.AddField( + model_name="pathway", + name="feature_sets", + field=models.ManyToManyField( + through="bionty.FeatureSetPathway", + to="lnschema_core.FeatureSet", + related_name="pathways", + ), + ), + migrations.RenameField( + model_name="artifactcellline", + old_name="cell_line", + new_name="cellline", + ), + migrations.RenameField( + model_name="artifactcellmarker", + old_name="cell_marker", + new_name="cellmarker", + ), + migrations.RenameField( + model_name="artifactcelltype", + old_name="cell_type", + new_name="celltype", + ), + migrations.RenameField( + model_name="artifactdevelopmentalstage", + old_name="developmental_stage", + new_name="developmentalstage", + ), + ] diff --git a/bionty/migrations/0028_artifactcellline_created_at_and_more.py b/bionty/migrations/0028_artifactcellline_created_at_and_more.py new file mode 100644 index 0000000..6bf366e --- /dev/null +++ b/bionty/migrations/0028_artifactcellline_created_at_and_more.py @@ -0,0 +1,703 @@ +# Generated by Django 5.0.6 on 2024-05-19 11:26 + +import django.db.models.deletion +import django.utils.timezone +import lnschema_core.models +import lnschema_core.users +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("bionty", "0027_remove_artifactcellline_created_at_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="artifactcellline", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactcellline", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactcellline", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactcellmarker", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactcellmarker", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactcellmarker", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactcelltype", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactcelltype", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactcelltype", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactdevelopmentalstage", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactdevelopmentalstage", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactdevelopmentalstage", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactdisease", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactdisease", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactdisease", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactethnicity", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactethnicity", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactethnicity", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactexperimentalfactor", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactexperimentalfactor", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactexperimentalfactor", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactgene", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactgene", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactgene", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactorganism", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactorganism", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactorganism", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactpathway", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactpathway", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactpathway", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactphenotype", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactphenotype", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactphenotype", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifactprotein", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifactprotein", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifactprotein", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="artifacttissue", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, db_index=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="artifacttissue", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AddField( + model_name="artifacttissue", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="cellline", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="cellline", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="cellmarker", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="cellmarker", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="celltype", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="celltype", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="developmentalstage", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="developmentalstage", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="disease", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="disease", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="ethnicity", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="ethnicity", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="experimentalfactor", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="experimentalfactor", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="gene", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="gene", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="organism", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="organism", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="pathway", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="pathway", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="phenotype", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="phenotype", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="protein", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="protein", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="publicsource", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="publicsource", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AddField( + model_name="tissue", + name="previous_runs", + field=models.ManyToManyField(to="lnschema_core.run"), + ), + migrations.AddField( + model_name="tissue", + name="run", + field=models.ForeignKey( + default=lnschema_core.models.current_run, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.run", + ), + ), + migrations.AlterField( + model_name="cellline", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="cellmarker", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="celltype", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="developmentalstage", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="disease", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="ethnicity", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="experimentalfactor", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="gene", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="organism", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="pathway", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="phenotype", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="protein", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="publicsource", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + migrations.AlterField( + model_name="tissue", + name="created_by", + field=models.ForeignKey( + default=lnschema_core.users.current_user_id, + on_delete=django.db.models.deletion.PROTECT, + to="lnschema_core.user", + ), + ), + ] diff --git a/bionty/migrations/0028_squashed.py b/bionty/migrations/0028_squashed.py index 2569f3d..617e225 100644 --- a/bionty/migrations/0028_squashed.py +++ b/bionty/migrations/0028_squashed.py @@ -10,7 +10,14 @@ class Migration(migrations.Migration): initial = True - + replaces = [ + ("bionty", "0023_rename_publicsource_encode_uid"), + ("bionty", "0024_remove_cellline_collections_and_more"), + ("bionty", "0025_artifactcellline_alter_cellline_artifacts_and_more"), + ("bionty", "0026_artifactcellline_cell_line_ref_is_name_and_more"), + ("bionty", "0027_remove_artifactcellline_created_at_and_more"), + ("bionty", "0028_artifactcellline_created_at_and_more"), + ] dependencies = [ ("lnschema_core", "0052_squashed"), ] diff --git a/bionty/migrations/0040_rename_feature_ref_is_symbol_artifactgene_feature_ref_is_name_and_more.py b/bionty/migrations/0040_rename_feature_ref_is_symbol_artifactgene_feature_ref_is_name_and_more.py index aac5b81..b35c0d8 100644 --- a/bionty/migrations/0040_rename_feature_ref_is_symbol_artifactgene_feature_ref_is_name_and_more.py +++ b/bionty/migrations/0040_rename_feature_ref_is_symbol_artifactgene_feature_ref_is_name_and_more.py @@ -1,6 +1,51 @@ # Generated by Django 5.1.1 on 2024-10-18 14:17 -from django.db import migrations +from django.db import connection, migrations + + +def remove_duplicate_entries(apps, schema_editor) -> None: + """Removes duplicate entries from ArtifactCellType table, keeping only one record + for each unique combination of artifact_id, celltype_id, and feature_id. + """ + import bionty as bt + + # SQL to identify and keep only one record from each group of duplicates + sql = """ + WITH duplicates AS ( + SELECT id, + ROW_NUMBER() OVER ( + PARTITION BY artifact_id, celltype_id, feature_id + ORDER BY id + ) as row_num + FROM bionty_artifactcelltype + ) + DELETE FROM bionty_artifactcelltype + WHERE id IN ( + SELECT id + FROM duplicates + WHERE row_num > 1 + ); + """ + + # Get count before deletion + count_before = bt.CellType.artifacts.through.objects.count() + + # Execute the SQL + with connection.cursor() as cursor: + cursor.execute(sql) + + # Get count after deletion + count_after = bt.CellType.artifacts.through.objects.count() + + # Return number of deleted records + print( + "ArtifactCellType links", + { + "records_before": count_before, + "records_after": count_after, + "duplicates_removed": count_before - count_after, + }, + ) class Migration(migrations.Migration): @@ -20,6 +65,7 @@ class Migration(migrations.Migration): old_name="gene_ref_is_symbol", new_name="label_ref_is_name", ), + migrations.RunPython(remove_duplicate_entries), migrations.AlterUniqueTogether( name="artifactcellline", unique_together={("artifact", "cellline", "feature")},