emails/migrations/0061_relayaddress_idx_ra_created_by_addon.py (31 lines of code) (raw):
# Generated by Django 4.2.11 on 2024-03-28 18:31
from django.db import migrations, models
def remove_incident_index(apps, schema_editor):
"""Remove the index manually added during the March 28, 2024 incident."""
if schema_editor.connection.vendor.startswith("postgres"):
schema_editor.execute("DROP INDEX IF EXISTS incident_glean_202403;")
def add_incident_index(apps, schema_editor):
"""Add the index manually added during the March 28, 2024 incident."""
if schema_editor.connection.vendor.startswith("postgres"):
schema_editor.execute(
"""
CREATE INDEX IF NOT EXISTS incident_glean_202403
ON emails_relayaddress (user_id)
INCLUDE (created_at)
WHERE (generated_for != '');
"""
)
class Migration(migrations.Migration):
dependencies = [
(
"emails",
"0060_add_num_deleted_relay_addresses_and_num_deleted_domain_addresses_to_profile", # noqa: E501
),
]
operations = [
migrations.AddIndex(
model_name="relayaddress",
index=models.Index(
condition=models.Q(("generated_for__exact", ""), _negated=True),
fields=["user"],
include=("created_at",),
name="idx_ra_created_by_addon",
),
),
migrations.RunPython(
code=remove_incident_index,
reverse_code=add_incident_index,
elidable=True,
),
]