From f10cd3aba5bb8451bcf8dce4434f32f268d3a206 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Tue, 6 Aug 2024 17:57:11 +0200 Subject: [PATCH] Create migration checking for old data requiring Lesrooster to be installed --- .../migrations/0024_check_new_models.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 aleksis/apps/alsijil/migrations/0024_check_new_models.py diff --git a/aleksis/apps/alsijil/migrations/0024_check_new_models.py b/aleksis/apps/alsijil/migrations/0024_check_new_models.py new file mode 100644 index 000000000..da52a8722 --- /dev/null +++ b/aleksis/apps/alsijil/migrations/0024_check_new_models.py @@ -0,0 +1,27 @@ +from django.db import migrations, models + +from django.apps import apps as global_apps + +def check_for_migration(apps, schema_editor): + if global_apps.is_installed('aleksis.apps.lesrooster'): + return + + ExcuseType = apps.get_model('alsijil', 'ExcuseType') + PersonalNote = apps.get_model('alsijil', 'PersonalNote') + LessonDocumentation = apps.get_model('alsijil', 'LessonDocumentation') + + model_types = [ExcuseType, PersonalNote, LessonDocumentation] + + for model in model_types: + if model.objects.exists(): + raise RuntimeError("You have legacy data. Please install AlekSIS-App-Lesrooster to migrate them.") + +class Migration(migrations.Migration): + + dependencies = [ + ('alsijil', '0023_add_tardiness_and_rework_constraints'), + ] + + operations = [ + migrations.RunPython(check_for_migration), + ] -- GitLab