Skip to content

Commit

Permalink
Resolve migration conflict, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kaapstorm committed Oct 19, 2024
1 parent fc0f174 commit ea918f3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 60 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Migration(migrations.Migration):

dependencies = [
("repeaters", "0013_alter_repeatrecord_state_and_more"),
("repeaters", "0014_alter_repeater_request_method"),
]

operations = [
Expand Down
44 changes: 44 additions & 0 deletions corehq/motech/repeaters/migrations/0016_add_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Adds an index for RepeatRecord.state and a partial index for
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


class Migration(migrations.Migration):
atomic = False

dependencies = [
("repeaters", "0015_repeater_max_workers"),
]

operations = [
# 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"
ON "repeaters_repeatrecord" ("state");
""",
reverse_sql="""
DROP INDEX CONCURRENTLY "repeaters_repeatrecord_state_8055083b";
"""
),

# Adds an index for Repeater.next_attempt_at when
# Repeater.is_paused is False. Builds it concurrently.
migrations.RunSQL(
sql="""
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";
"""
)
]
2 changes: 2 additions & 0 deletions migrations.lock
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ repeaters
0012_formexpressionrepeater_arcgisformexpressionrepeater
0013_alter_repeatrecord_state_and_more
0014_alter_repeater_request_method
0015_repeater_max_workers
0016_add_indexes
reports
0001_initial
0002_auto_20171121_1803
Expand Down

0 comments on commit ea918f3

Please sign in to comment.