Skip to content

Commit

Permalink
Fix revert migration
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolineDenis committed Oct 23, 2024
1 parent 54c3667 commit 22e7493
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions specifyweb/specify/migrations/0007_tectonic_ranks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ def create_default_tectonic_ranks(apps):

def revert_default_tectonic_ranks(apps, schema_editor):
TectonicUnit = apps.get_model('specify', 'TectonicUnit')
TectonicUnitTreeDefItem = apps.get_model('specify', 'TectonicUnitTreeDefItem')
TectonicTreeDef = apps.get_model('specify', 'TectonicUnitTreeDef')
Discipline = apps.get_model('specify', 'Discipline')

for discipline in Discipline.objects.all():
tectonic_tree_def = TectonicTreeDef.objects.filter(name="Tectonic Unit", discipline=discipline)
if tectonic_tree_def:
tectonic_tree_defs = TectonicTreeDef.objects.filter(name="Tectonic Unit", discipline=discipline)

for tectonic_tree_def in tectonic_tree_defs:
tectonic_unit_tree_def_items = TectonicUnitTreeDefItem.objects.filter(treedef=tectonic_tree_def).order_by('-id')

for item in tectonic_unit_tree_def_items:
TectonicUnit.objects.filter(definitionitem=item).delete()

item.delete()

tectonic_tree_def.delete()

def create_root_tectonic_node(apps):
Expand Down Expand Up @@ -93,13 +102,15 @@ def create_root_tectonic_node(apps):

def revert_create_root_tectonic_node(apps, schema_editor):
TectonicUnit = apps.get_model('specify', 'TectonicUnit')
TectonicUnitTreeDefItem = apps.get_model('specify', 'TectonicUnitTreeDefItem')
TectonicTreeDef = apps.get_model('specify', 'TectonicUnitTreeDef')
Discipline = apps.get_model('specify', 'Discipline')

for discipline in Discipline.objects.all():
tectonic_tree_def = TectonicTreeDef.objects.filter(name="Tectonic Unit", discipline=discipline).first()

if tectonic_tree_def:
TectonicUnitTreeDefItem.objects.filter(treedef=tectonic_tree_def).delete()
TectonicUnit.objects.filter(
name="Root"
).delete()
Expand All @@ -116,7 +127,7 @@ def consolidated_python_django_migration_operations(apps, schema_editor):

def revert_cosolidated_python_django_migration_operations(apps, schema_editor):
revert_default_tectonic_ranks(apps, schema_editor)
revert_create_root_tectonic_node(apps)
revert_create_root_tectonic_node(apps, schema_editor)

operations = [
migrations.RunPython(consolidated_python_django_migration_operations, revert_cosolidated_python_django_migration_operations, atomic=True),
Expand Down

0 comments on commit 22e7493

Please sign in to comment.