# Codelist migration optimization

* adds boolean to de-/activate migration logic inside of 0002_migrate_975_to_288.py
pull/434/head
mpeltriaux 2 months ago
parent 4e56f47b47
commit e9f9420f0f

@ -1,5 +1,6 @@
# Generated by Django 5.0.7 on 2024-08-06 13:40 # Generated by Django 5.0.7 on 2024-08-06 13:40
from django.core.exceptions import ObjectDoesNotExist
from django.db import migrations from django.db import migrations
from django.db.models import Q from django.db.models import Q
@ -10,9 +11,12 @@ def migrate_975_to_288(apps, schema_editor):
KonovaCodeList = apps.get_model('codelist', 'KonovaCodeList') KonovaCodeList = apps.get_model('codelist', 'KonovaCodeList')
CompensationState = apps.get_model('compensation', 'CompensationState') CompensationState = apps.get_model('compensation', 'CompensationState')
try:
list_288 = KonovaCodeList.objects.get( list_288 = KonovaCodeList.objects.get(
id=CODELIST_BIOTOPES_EXTRA_CODES_FULL_ID id=CODELIST_BIOTOPES_EXTRA_CODES_FULL_ID
).codes.all() ).codes.all()
except ObjectDoesNotExist:
raise AssertionError("KonovaCodeList 288 does not exist. Did you run 'update_codelist' before migrating?")
states_with_extra_code = CompensationState.objects.filter( states_with_extra_code = CompensationState.objects.filter(
~Q(biotope_type_details=None) ~Q(biotope_type_details=None)
@ -42,8 +46,15 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
('codelist', '0001_initial'), ('codelist', '0001_initial'),
('compensation', '0003_auto_20220202_0846'),
] ]
operations = [ # If migration of codelist is not necessary, this variable can shut down the logic whilst not disturbing the
migrations.RunPython(migrate_975_to_288) # migration history
] EXECUTE_CODELIST_MIGRATION = True
operations = []
if EXECUTE_CODELIST_MIGRATION:
operations.append(migrations.RunPython(migrate_975_to_288))

Loading…
Cancel
Save