From 811096d83dc713ed3e33fa6b82fd621721566db7 Mon Sep 17 00:00:00 2001 From: Sharad S Date: Thu, 7 Nov 2024 12:59:26 -0500 Subject: [PATCH 1/3] Add cojo to Schema Config --- .../0012_add_cojo_to_schema_config.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 specifyweb/specify/migrations/0012_add_cojo_to_schema_config.py diff --git a/specifyweb/specify/migrations/0012_add_cojo_to_schema_config.py b/specifyweb/specify/migrations/0012_add_cojo_to_schema_config.py new file mode 100644 index 00000000000..23882c73f29 --- /dev/null +++ b/specifyweb/specify/migrations/0012_add_cojo_to_schema_config.py @@ -0,0 +1,31 @@ +""" +This migration adds COG -> cojo and CO -> cojo to Schema Config. +""" +from django.db import migrations +from specifyweb.specify.update_schema_config import revert_table_field_schema_config, update_table_field_schema_config_with_defaults + +def add_cojo_to_schema_config(apps): + Discipline = apps.get_model('specify', 'Discipline') + for discipline in Discipline.objects.all(): + update_table_field_schema_config_with_defaults('CollectionObjectGroup', discipline.id, 'cojo', apps) + update_table_field_schema_config_with_defaults('CollectionObject', discipline.id, 'cojo', apps) + +def remove_cojo_from_schema_config(apps): + revert_table_field_schema_config('CollectionObjectGroup', 'cojo', apps) + revert_table_field_schema_config('CollectionObject', 'cojo', apps) + +class Migration(migrations.Migration): + + dependencies = [ + ('specify', '0011_cascading_tree_nodes'), + ] + + def apply_migration(apps, schema_editor): + add_cojo_to_schema_config(apps) + + def revert_migration(apps, schema_editor): + remove_cojo_from_schema_config(apps) + + operations = [ + migrations.RunPython(apply_migration, revert_migration, atomic=True), + ] \ No newline at end of file From 743cdffc6e7a2181382381ca9abefeca3d40e78f Mon Sep 17 00:00:00 2001 From: Sharad S Date: Fri, 8 Nov 2024 13:19:47 -0500 Subject: [PATCH 2/3] Remove duplicate children field --- specifyweb/specify/migrations/0007_schema_config_update.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specifyweb/specify/migrations/0007_schema_config_update.py b/specifyweb/specify/migrations/0007_schema_config_update.py index 0db00f68cfa..f3cbad646f7 100644 --- a/specifyweb/specify/migrations/0007_schema_config_update.py +++ b/specifyweb/specify/migrations/0007_schema_config_update.py @@ -26,6 +26,8 @@ def update_fields(apps): Splocalecontaineritem = apps.get_model('specify', 'Splocalecontaineritem') Splocaleitemstr = apps.get_model('specify', 'Splocaleitemstr') + # Revert COG -> children before adding to avoid duplicates + revert_table_field_schema_config('CollectionObjectGroup', 'children', apps) # Add StorageTreeDef -> institution and COG -> children for discipline in Discipline.objects.all(): update_table_field_schema_config_with_defaults('StorageTreeDef', discipline.id, 'institution', apps) From 06c8b058d943c015daac08d25ba3f248d1d9b7eb Mon Sep 17 00:00:00 2001 From: Sharad S Date: Tue, 12 Nov 2024 09:52:19 -0500 Subject: [PATCH 3/3] Avoid recreating ranks and nodes --- .../specify/migrations/0009_tectonic_ranks.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/specifyweb/specify/migrations/0009_tectonic_ranks.py b/specifyweb/specify/migrations/0009_tectonic_ranks.py index ab000082522..487d30ab907 100644 --- a/specifyweb/specify/migrations/0009_tectonic_ranks.py +++ b/specifyweb/specify/migrations/0009_tectonic_ranks.py @@ -7,44 +7,44 @@ def create_default_tectonic_ranks(apps): TectonicTreeDef = apps.get_model('specify', 'TectonicUnitTreeDef') Discipline = apps.get_model('specify', 'Discipline') for discipline in Discipline.objects.all(): - tectonic_tree_def = TectonicTreeDef.objects.create(name="Tectonic Unit", discipline=discipline) + tectonic_tree_def, _ = TectonicTreeDef.objects.get_or_create(name="Tectonic Unit", discipline=discipline) - root = TectonicUnitTreeDefItem.objects.create( + root, _ = TectonicUnitTreeDefItem.objects.get_or_create( name="Root", title="Root", rankid=0, parent=None, treedef=tectonic_tree_def, ) - superstructure = TectonicUnitTreeDefItem.objects.create( + superstructure, _ = TectonicUnitTreeDefItem.objects.get_or_create( name="Superstructure", title="Superstructure", rankid=10, parent=root, treedef=tectonic_tree_def, ) - tectonic_domain = TectonicUnitTreeDefItem.objects.create( + tectonic_domain, _ = TectonicUnitTreeDefItem.objects.get_or_create( name="Tectonic Domain", title="Tectonic Domain", rankid=20, parent=superstructure, treedef=tectonic_tree_def, ) - tectonic_subdomain = TectonicUnitTreeDefItem.objects.create( + tectonic_subdomain, _ = TectonicUnitTreeDefItem.objects.get_or_create( name="Tectonic Subdomain", title="Tectonic Subdomain", rankid=30, parent=tectonic_domain, treedef=tectonic_tree_def, ) - tectonic_unit = TectonicUnitTreeDefItem.objects.create( + tectonic_unit, _ = TectonicUnitTreeDefItem.objects.get_or_create( name="Tectonic Unit", title="Tectonic Unit", rankid=40, parent=tectonic_subdomain, treedef=tectonic_tree_def, ) - tectonic_subunit = TectonicUnitTreeDefItem.objects.create( + tectonic_subunit, _ = TectonicUnitTreeDefItem.objects.get_or_create( name="Tectonic Subunit", title="Tectonic Subunit", rankid=50, @@ -94,7 +94,7 @@ def create_root_tectonic_node(apps): treedef=tectonic_tree_def ) - root = TectonicUnit.objects.create( + root, _ = TectonicUnit.objects.get_or_create( name="Root", isaccepted=1, nodenumber=1,