From 09962aa6f42b3b1deae2d1cfa36ef2ac488d59de Mon Sep 17 00:00:00 2001 From: payyup Date: Fri, 28 Jul 2023 11:31:55 +0530 Subject: [PATCH 1/2] SN-791: migration change --- .../migrations/0046_auto_20230727_0728.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/tasks/migrations/0046_auto_20230727_0728.py b/backend/tasks/migrations/0046_auto_20230727_0728.py index a21c35dca..ab134e2a0 100644 --- a/backend/tasks/migrations/0046_auto_20230727_0728.py +++ b/backend/tasks/migrations/0046_auto_20230727_0728.py @@ -1,17 +1,24 @@ # Generated by Django 3.2.14 on 2023-07-27 07:28 from django.db import migrations +from django.core.paginator import Paginator def update_annotated_at(apps, schema_editor): Annotation = apps.get_model("tasks", "Annotation") - objs = [] - for annotation in Annotation.objects.all().iterator(): - if annotation.annotated_at is None: - annotation.annotated_at = annotation.updated_at - objs.append(annotation) + queryset = Annotation.objects.all() + paginator = Paginator(queryset, 10000) - Annotation.objects.bulk_update(objs, ["annotated_at"], batch_size=1000) + for page_number in paginator.page_range: + chunk = paginator.page(page_number) + objs = [] + + for annotation in chunk.object_list: + if annotation.annotated_at is None: + annotation.annotated_at = annotation.updated_at + objs.append(annotation) + + Annotation.objects.bulk_update(objs, ["annotated_at"]) class Migration(migrations.Migration): From 0dd667250052f5cd9c145cdfbd669ff7288b5ef5 Mon Sep 17 00:00:00 2001 From: payyup Date: Fri, 28 Jul 2023 12:21:39 +0530 Subject: [PATCH 2/2] SN-791: migrations --- .../migrations/0046_auto_20230727_0728.py | 2 +- .../0047_alter_annotation_annotated_at.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 backend/tasks/migrations/0047_alter_annotation_annotated_at.py diff --git a/backend/tasks/migrations/0046_auto_20230727_0728.py b/backend/tasks/migrations/0046_auto_20230727_0728.py index ab134e2a0..3e50d062e 100644 --- a/backend/tasks/migrations/0046_auto_20230727_0728.py +++ b/backend/tasks/migrations/0046_auto_20230727_0728.py @@ -6,7 +6,7 @@ def update_annotated_at(apps, schema_editor): Annotation = apps.get_model("tasks", "Annotation") - queryset = Annotation.objects.all() + queryset = Annotation.objects.all().order_by("id") paginator = Paginator(queryset, 10000) for page_number in paginator.page_range: diff --git a/backend/tasks/migrations/0047_alter_annotation_annotated_at.py b/backend/tasks/migrations/0047_alter_annotation_annotated_at.py new file mode 100644 index 000000000..62adda041 --- /dev/null +++ b/backend/tasks/migrations/0047_alter_annotation_annotated_at.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.14 on 2023-07-28 06:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tasks", "0046_auto_20230727_0728"), + ] + + operations = [ + migrations.AlterField( + model_name="annotation", + name="annotated_at", + field=models.DateTimeField( + blank=True, + help_text="Time when the annotation was first labeled/accepted/validated", + null=True, + verbose_name="annotation_annotated_at", + ), + ), + ]