diff --git a/onadata/apps/logger/migrations/0011_add_xform_id_instance_id_idx.py b/onadata/apps/logger/migrations/0011_add_xform_id_instance_id_idx.py new file mode 100644 index 0000000000..9b5764c6ea --- /dev/null +++ b/onadata/apps/logger/migrations/0011_add_xform_id_instance_id_idx.py @@ -0,0 +1,31 @@ +# Generated by Django 3.2.20 on 2023-11-23 16:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + atomic = False + + dependencies = [ + ('logger', '0010_auto_20230921_0346'), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + database_operations=[ + # index the json date fields + migrations.RunSQL( + sql='CREATE INDEX CONCURRENTLY "logger_instance_id_xform_id_index" ON "logger_instance" ("xform_id", "id");', + reverse_sql='DROP INDEX "logger_instance_id_xform_id_index";', + ), + ], + state_operations=[ + migrations.AddIndex( + model_name="instance", + index=models.Index( + fields=["xform_id", "id"], name="logger_instance_id_xform_id_index" + ), + ), + ], + ) + ] diff --git a/onadata/apps/logger/models/instance.py b/onadata/apps/logger/models/instance.py index fe32914da2..2c0fd87d12 100644 --- a/onadata/apps/logger/models/instance.py +++ b/onadata/apps/logger/models/instance.py @@ -685,6 +685,7 @@ class Meta: models.Index(fields=["date_created"]), models.Index(fields=["date_modified"]), models.Index(fields=["deleted_at"]), + models.Index(fields=["xform_id", "id"]), ] @classmethod