Skip to content

Commit

Permalink
Merge pull request #790 from AI4Bharat/SN-791-new
Browse files Browse the repository at this point in the history
SN-791: migration change
  • Loading branch information
ishvindersethi22 authored Jul 28, 2023
2 parents a209cd9 + 0dd6672 commit dd85aab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/tasks/migrations/0046_auto_20230727_0728.py
Original file line number Diff line number Diff line change
@@ -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().order_by("id")
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):
Expand Down
22 changes: 22 additions & 0 deletions backend/tasks/migrations/0047_alter_annotation_annotated_at.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]

0 comments on commit dd85aab

Please sign in to comment.