|
| 1 | +# Generated by Django 3.2.23 on 2024-02-22 05:45 |
| 2 | +from django.db import migrations |
| 3 | +from django.db import models |
| 4 | + |
| 5 | +from api.logger import logger |
| 6 | + |
| 7 | + |
| 8 | +class Migration(migrations.Migration): |
| 9 | + def migrate_formdata_notes(apps, schema_editor): |
| 10 | + # NOTE: No any exact match for relationships |
| 11 | + FormComponentResponse = apps.get_model("per", "FormComponentResponse") |
| 12 | + FormData = apps.get_model("per", "FormData") |
| 13 | + qs = FormComponentResponse.objects.annotate( |
| 14 | + new_notes=models.Subquery( |
| 15 | + FormData.objects.filter( |
| 16 | + question__component=models.OuterRef("component"), |
| 17 | + question=74, |
| 18 | + ) |
| 19 | + .order_by( |
| 20 | + "-form__area", |
| 21 | + "-form__created_at", |
| 22 | + "form", |
| 23 | + "question__question_num", |
| 24 | + ) |
| 25 | + .filter(notes__isnull=False) |
| 26 | + .values("notes_en")[:1], |
| 27 | + output_field=models.CharField(), |
| 28 | + ), |
| 29 | + ).filter(new_notes__isnull=False) |
| 30 | + |
| 31 | + print( |
| 32 | + qs.update( |
| 33 | + notes=models.F("new_notes"), |
| 34 | + ) |
| 35 | + ) |
| 36 | + |
| 37 | + dependencies = [ |
| 38 | + ("per", "0098_fix_reversion_data_20240208_0502"), |
| 39 | + ] |
| 40 | + |
| 41 | + operations = [ |
| 42 | + migrations.RunPython(migrate_formdata_notes, reverse_code=migrations.RunPython.noop), |
| 43 | + ] |
0 commit comments