Skip to content

Commit

Permalink
Missed a "concurrently"! Added comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaapstorm committed Oct 19, 2024
1 parent 7e65b3b commit 8da8851
Showing 1 changed file with 12 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Expand All @@ -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";
Expand Down

0 comments on commit 8da8851

Please sign in to comment.