From 31f4369236aece7372028923255d8fbea95a1c90 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 18 Feb 2022 09:26:29 +0100 Subject: [PATCH] Missing migration * adds a migration which has not been checked in from another branch --- .../migrations/0005_auto_20220218_0917.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 compensation/migrations/0005_auto_20220218_0917.py diff --git a/compensation/migrations/0005_auto_20220218_0917.py b/compensation/migrations/0005_auto_20220218_0917.py new file mode 100644 index 00000000..43e7db9c --- /dev/null +++ b/compensation/migrations/0005_auto_20220218_0917.py @@ -0,0 +1,46 @@ +# Generated by Django 3.1.3 on 2022-02-18 08:17 + +from django.db import migrations, models, transaction +import django.db.models.deletion + +from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_AFTER_STATE_BIOTOPES__ID + + +def migrate_entries_974_to_654(apps, schema_editor): + CompensationState = apps.get_model("compensation", "CompensationState") + KonovaCode = apps.get_model("codelist", "KonovaCode") + all_states = CompensationState.objects.all() + + with transaction.atomic(): + for state in all_states: + code_from_654 = KonovaCode.objects.get( + short_name=state.biotope_type.short_name, + code_lists__in=[CODELIST_BIOTOPES_ID], + is_archived=False, + is_leaf=True, + ) + state.biotope_type = code_from_654 + state.save() + + old_list_states = CompensationState.objects.filter( + biotope_type__code_lists__in=[CODELIST_AFTER_STATE_BIOTOPES__ID] + ) + if old_list_states.count() > 0: + raise Exception("Still unmigrated values!") + + +class Migration(migrations.Migration): + + dependencies = [ + ('codelist', '0001_initial'), + ('compensation', '0004_auto_20220210_1402'), + ] + + operations = [ + migrations.RunPython(migrate_entries_974_to_654), + migrations.AlterField( + model_name='compensationstate', + name='biotope_type', + field=models.ForeignKey(blank=True, limit_choices_to={'code_lists__in': [654], 'is_archived': False, 'is_selectable': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='codelist.konovacode'), + ), + ]