From 5080ab98e8b65a166c50990967d25800d77f65e8 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Tue, 6 Aug 2024 17:57:01 +0200
Subject: [PATCH] Create migration checking for old data requiring Lesrooster
 to be installed

---
 .../migrations/0018_check_new_models.py       | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 aleksis/apps/chronos/migrations/0018_check_new_models.py

diff --git a/aleksis/apps/chronos/migrations/0018_check_new_models.py b/aleksis/apps/chronos/migrations/0018_check_new_models.py
new file mode 100644
index 00000000..144a1af5
--- /dev/null
+++ b/aleksis/apps/chronos/migrations/0018_check_new_models.py
@@ -0,0 +1,30 @@
+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
+
+    ValidityRange = apps.get_model('chronos', 'ValidityRange')
+    Subject = apps.get_model('chronos', 'Subject')
+    AbsenceReason = apps.get_model('chronos', 'AbsenceReason')
+    Absence = apps.get_model('chronos', 'Absence')
+    Holiday = apps.get_model('chronos', 'Holiday')
+    SupervisionArea = apps.get_model('chronos', 'SupervisionArea')
+
+    model_types = [ValidityRange, Subject, AbsenceReason, Absence, Holiday, SupervisionArea]
+
+    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 = [
+        ('chronos', '0017_optional_slot_number'),
+    ]
+
+    operations = [
+        migrations.RunPython(check_for_migration),
+    ]
-- 
GitLab