diff --git a/corehq/motech/repeaters/migrations/0015_alter_repeatrecord_state_and_more.py b/corehq/motech/repeaters/migrations/0015_alter_repeatrecord_state_and_more.py index 3d7f8ccd6ef5d..db3405f1366fd 100644 --- a/corehq/motech/repeaters/migrations/0015_alter_repeatrecord_state_and_more.py +++ b/corehq/motech/repeaters/migrations/0015_alter_repeatrecord_state_and_more.py @@ -1,6 +1,8 @@ """ Adds an index for RepeatRecord.state and a partial index for -next_attempt_at + not_paused +next_attempt_at + not_paused. The indexes are used by +RepeaterManager.all_ready() to select all Repeaters that have +RepeatRecords that are ready to be sent. """ from django.db import migrations @@ -13,23 +15,10 @@ class Migration(migrations.Migration): ] operations = [ - # migrations.AlterField( - # model_name="repeatrecord", - # name="state", - # field=models.PositiveSmallIntegerField( - # choices=[ - # (1, "Pending"), - # (2, "Failed"), - # (4, "Succeeded"), - # (8, "Cancelled"), - # (16, "Empty"), - # (32, "Invalid Payload"), - # ], - # db_index=True, - # default=1, - # ), - # ), - # Equivalent to the migration above, but builds the index concurrently + # Adds an index for RepeatRecord.state. Builds it concurrently. + # The SQL and the index name were determined from the generated + # Django migration. The migration was made concurrent by setting + # `atomic = False` and adding "CONCURRENTLY" to the SQL. migrations.RunSQL( sql=""" CREATE INDEX CONCURRENTLY "repeaters_repeatrecord_state_8055083b" @@ -40,17 +29,13 @@ class Migration(migrations.Migration): """ ), - # migrations.AddIndex( - # model_name="repeater", - # index=models.Index( - # condition=models.Q(("is_paused", False)), - # fields=["next_attempt_at"], - # name="next_attempt_at_not_paused_idx", - # ), - # ), + # Adds an index for Repeater.next_attempt_at when + # Repeater.is_paused is False. Builds it concurrently. migrations.RunSQL( sql=""" - CREATE INDEX "next_attempt_at_not_paused_idx" ON "repeaters_repeater" ("next_attempt_at") WHERE NOT "is_paused"; + CREATE INDEX CONCURRENTLY "next_attempt_at_not_paused_idx" + ON "repeaters_repeater" ("next_attempt_at") + WHERE NOT "is_paused"; """, reverse_sql=""" DROP INDEX CONCURRENTLY "next_attempt_at_not_paused_idx";