diff --git a/onadata/apps/logger/migrations/0005_add_date_fields_indexing.py b/onadata/apps/logger/migrations/0005_add_date_fields_indexing.py index f5af866ac6..b789dd441d 100644 --- a/onadata/apps/logger/migrations/0005_add_date_fields_indexing.py +++ b/onadata/apps/logger/migrations/0005_add_date_fields_indexing.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.18 on 2023-03-14 12:22 +# Generated by Django 3.2.20 on 2023-08-06 13:39 from django.db import migrations, models @@ -13,42 +13,49 @@ class Migration(migrations.Migration): operations = [ migrations.SeparateDatabaseAndState( database_operations=[ + # index the json date fields migrations.RunSQL( - sql='CREATE INDEX CONCURRENTLY "logger_inst_date_cr_42899d_idx" ON "logger_instance" ("date_created");', + sql='CREATE INDEX CONCURRENTLY "logger_inst_date_cr_json_42899d_idx" ON "logger_instance" ((json->>\'_date_created\')) WHERE (json->>\'_date_created\') IS NOT NULL;', + reverse_sql='DROP INDEX "logger_inst_date_cr_json_42899d_idx";', + ), + migrations.RunSQL( + sql='CREATE INDEX CONCURRENTLY "logger_inst_date_mo_json_5a1bd3_idx" ON "logger_instance" ((json->>\'_date_modified\')) WHERE (json->>\'_date_modified\') IS NOT NULL;', + reverse_sql='DROP INDEX "logger_inst_date_mo_json_5a1bd3_idx";', + ), + migrations.RunSQL( + sql='CREATE INDEX CONCURRENTLY "logger_inst_deleted_at_json_da31a3_idx" ON "logger_instance" ((json->>\'_deleted_at\')) WHERE (json->>\'_deleted_at\') IS NOT NULL;', + reverse_sql='DROP INDEX "logger_inst_deleted_at_json_da31a3_idx";', + ), + # index model date fields + migrations.RunSQL( + sql='CREATE INDEX "logger_inst_date_cr_42899d_idx" ON "logger_instance" ("date_created");', reverse_sql='DROP INDEX "logger_inst_date_cr_42899d_idx";', ), migrations.RunSQL( - sql='CREATE INDEX CONCURRENTLY "logger_inst_date_mo_5a1bd3_idx" ON "logger_instance" ("date_modified");', + sql='CREATE INDEX "logger_inst_date_mo_5a1bd3_idx" ON "logger_instance" ("date_modified");', reverse_sql='DROP INDEX "logger_inst_date_mo_5a1bd3_idx";', ), migrations.RunSQL( - sql='CREATE INDEX CONCURRENTLY "logger_inst_deleted_da31a3_idx" ON "logger_instance" ("deleted_at");', - reverse_sql='DROP INDEX "logger_inst_deleted_da31a3_idx";', + sql='CREATE INDEX "logger_inst_deleted_at_da31a3_idx" ON "logger_instance" ("deleted_at");', + reverse_sql='DROP INDEX "logger_inst_deleted_at_da31a3_idx";', ), ], state_operations=[ - migrations.AddIndex( + migrations.AlterField( model_name="instance", - index=models.Index( - fields=["date_created"], name="logger_inst_date_cr_42899d_idx" - ), + name="date_created", + field=models.DateTimeField(auto_now_add=True, db_index=True), ), - migrations.AddIndex( + migrations.AlterField( model_name="instance", - index=models.Index( - fields=["date_modified"], name="logger_inst_date_mo_5a1bd3_idx" - ), + name="date_modified", + field=models.DateTimeField(auto_now=True, db_index=True), ), - migrations.AddIndex( + migrations.AlterField( model_name="instance", - index=models.Index( - fields=["deleted_at"], name="logger_inst_deleted_da31a3_idx" - ), + name="deleted_at", + field=models.DateTimeField(auto_now=True, db_index=True), ), ], ) ] - - - -