|
| 1 | +# Generated by Django 5.2.6 on 2025-09-29 12:47 |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | +from django.db.models import Value |
| 5 | +from django.db.models.functions import Lower, Replace, Upper |
| 6 | + |
| 7 | + |
| 8 | +def rename_ids(apps, schema_editor): |
| 9 | + SymptomType = apps.get_model("participants", "SymptomType") |
| 10 | + SymptomSubType = apps.get_model("participants", "SymptomSubType") |
| 11 | + Symptom = apps.get_model("participants", "Symptom") |
| 12 | + |
| 13 | + SymptomType.objects.update(id=Upper(Replace("id", Value("-"), Value("_")))) |
| 14 | + SymptomSubType.objects.update( |
| 15 | + id=Upper(Replace("id", Value("-"), Value("_"))), |
| 16 | + symptom_type=Upper(Replace("symptom_type", Value("-"), Value("_"))), |
| 17 | + ) |
| 18 | + Symptom.objects.update( |
| 19 | + symptom_type=Upper(Replace("symptom_type", Value("-"), Value("_"))) |
| 20 | + ) |
| 21 | + Symptom.objects.update( |
| 22 | + symptom_sub_type=Upper(Replace("symptom_sub_type", Value("-"), Value("_"))) |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +def revert_ids(apps, schema_editor): |
| 27 | + SymptomType = apps.get_model("participants", "SymptomType") |
| 28 | + SymptomSubType = apps.get_model("participants", "SymptomSubType") |
| 29 | + Symptom = apps.get_model("participants", "Symptom") |
| 30 | + |
| 31 | + SymptomType.objects.update(id=Lower(Replace("id", Value("_"), Value("-")))) |
| 32 | + SymptomSubType.objects.update( |
| 33 | + id=Lower(Replace("id", Value("_"), Value("-"))), |
| 34 | + symptom_type=Lower(Replace("symptom_type", Value("_"), Value("-"))), |
| 35 | + ) |
| 36 | + Symptom.objects.update( |
| 37 | + symptom_type=Lower(Replace("symptom_type", Value("_"), Value("-"))) |
| 38 | + ) |
| 39 | + Symptom.objects.update( |
| 40 | + symptom_sub_type=Lower(Replace("symptom_sub_type", Value("_"), Value("-"))) |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | +class Migration(migrations.Migration): |
| 45 | + |
| 46 | + dependencies = [ |
| 47 | + ("participants", "0029_symptom_symptom_sub_type_details"), |
| 48 | + ] |
| 49 | + |
| 50 | + operations = [ |
| 51 | + migrations.RunPython(rename_ids, revert_ids), |
| 52 | + ] |
0 commit comments