-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from MetaCell/feature/CSCKAN-290
Feature/csckan-290 - change region/layer model to be independent models from AEMeta - and related changes
- Loading branch information
Showing
16 changed files
with
603 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
backend/composer/migrations/0053_alter_anatomicalentity_options_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Generated by Django 4.1.4 on 2024-07-08 13:18 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def populate_intersection_anatomical_entity_meta_id_from_layer_region(apps, schema_editor): | ||
""" | ||
populating the new fields from AnatomicalEntityIntersection | ||
layer_id -> layer_meta_id | ||
region_id -> region_meta_id | ||
""" | ||
AnatomicalEntityIntersection = apps.get_model("composer", "AnatomicalEntityIntersection") | ||
for intersection in AnatomicalEntityIntersection.objects.all(): | ||
intersection.layer_meta_id = intersection.layer_id | ||
intersection.region_meta_id = intersection.region_id | ||
intersection.save() | ||
|
||
|
||
def populate_layer_region_ae_meta_ids_from_anatomicalentitymeta_ptr_id(apps, schema_editor): | ||
""" | ||
populating the new fields from Layer and Region | ||
anatomicalentitymeta_ptr_id -> layer_ae_meta_id | ||
anatomicalentitymeta_ptr_id -> region_ae_meta_id | ||
""" | ||
Layer = apps.get_model("composer", "Layer") | ||
Region = apps.get_model("composer", "Region") | ||
|
||
for layer in Layer.objects.all(): | ||
layer.layer_ae_meta_id = layer.anatomicalentitymeta_ptr_id | ||
layer.save() | ||
|
||
for region in Region.objects.all(): | ||
region.region_ae_meta_id = region.anatomicalentitymeta_ptr_id | ||
region.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("composer", "0052_alter_anatomicalentity_options_and_more"), | ||
] | ||
|
||
# Steps taken in migration: | ||
# 1. create new fields for layer and region - layer_ae_meta, region_ae_meta | ||
# 2. create new fields for AnatomicalEntityIntersection - layer_meta, region_meta | ||
# 3. populate the new fields in AnatomicalEntityIntersection from the old fields - layer, region | ||
# 4. populate the new fields in Layer and Region from the old fields - anatomicalentitymeta_ptr_id | ||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="anatomicalentity", | ||
options={ | ||
"verbose_name": "Anatomical Entity", | ||
"verbose_name_plural": "Anatomical Entities", | ||
}, | ||
), | ||
|
||
migrations.AddField( | ||
model_name="layer", | ||
name="layer_ae_meta", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="layer_meta", | ||
to="composer.anatomicalentitymeta", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="region", | ||
name="region_ae_meta", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="region_meta", | ||
to="composer.anatomicalentitymeta", | ||
), | ||
), | ||
|
||
# ------------------------ | ||
migrations.AddField( | ||
model_name="anatomicalentityintersection", | ||
name="layer_meta", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="layer_intersection", | ||
to="composer.anatomicalentitymeta", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="anatomicalentityintersection", | ||
name="region_meta", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="region_intersection", | ||
to="composer.anatomicalentitymeta", | ||
), | ||
), | ||
|
||
# ------------------------ | ||
|
||
migrations.RunPython( | ||
code=populate_intersection_anatomical_entity_meta_id_from_layer_region, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
|
||
# ------------------------ | ||
|
||
migrations.RunPython( | ||
code=populate_layer_region_ae_meta_ids_from_anatomicalentitymeta_ptr_id, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
|
||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Generated by Django 4.1.4 on 2024-07-09 07:09 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("composer", "0053_alter_anatomicalentity_options_and_more"), | ||
] | ||
|
||
# Steps taken in migration: | ||
# 1. create new models for layer and region - NewLayer, NewRegion | ||
# 2. copy the necessary columns from the old models to the new models - layer_ae_meta, region_ae_meta | ||
# 3. remove the old models - Layer, Region and it's fk from AnatomicalEntityIntersection | ||
# 4. rename the new models to the old models - Layer, Region | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="NewLayer", | ||
fields=[ | ||
( | ||
"layer_id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
( | ||
"layer_ae_meta", | ||
models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="layer_meta", | ||
to="composer.anatomicalentitymeta", | ||
), | ||
) | ||
] | ||
), | ||
migrations.RunSQL( | ||
sql="INSERT INTO composer_newlayer (layer_ae_meta_id) SELECT anatomicalentitymeta_ptr_id FROM composer_layer", | ||
reverse_sql="", | ||
), | ||
migrations.RemoveField( | ||
model_name="anatomicalentityintersection", | ||
name="layer", | ||
), | ||
migrations.DeleteModel( | ||
name="Layer", | ||
), | ||
migrations.RenameModel( | ||
old_name="NewLayer", | ||
new_name="Layer", | ||
), | ||
|
||
|
||
# ---------------------------- | ||
migrations.CreateModel( | ||
name="NewRegion", | ||
fields=[ | ||
( | ||
"region_id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
( | ||
"region_ae_meta", | ||
models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="region_meta", | ||
to="composer.anatomicalentitymeta", | ||
), | ||
) | ||
] | ||
), | ||
migrations.RunSQL( | ||
sql="INSERT INTO composer_newregion (region_ae_meta_id) SELECT anatomicalentitymeta_ptr_id FROM composer_region", | ||
reverse_sql="", | ||
), | ||
migrations.RemoveField( | ||
model_name="anatomicalentityintersection", | ||
name="region", | ||
), | ||
migrations.DeleteModel( | ||
name="Region", | ||
), | ||
migrations.RenameModel( | ||
old_name="NewRegion", | ||
new_name="Region", | ||
), | ||
|
||
|
||
|
||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.1.4 on 2024-07-08 13:40 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("composer", "0054_auto_20240709_0909"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="layer", | ||
options={"verbose_name": "Layer", "verbose_name_plural": "Layers"}, | ||
), | ||
migrations.AlterModelOptions( | ||
name="region", | ||
options={"verbose_name": "Region", "verbose_name_plural": "Regions"}, | ||
), | ||
migrations.RenameField( | ||
model_name="anatomicalentityintersection", | ||
old_name="layer_meta", | ||
new_name="layer", | ||
), | ||
migrations.RenameField( | ||
model_name="anatomicalentityintersection", | ||
old_name="region_meta", | ||
new_name="region", | ||
), | ||
] |
Oops, something went wrong.