Skip to content

Commit a7cd961

Browse files
committed
Add composite template index on notification history
This is a temporary change to allow us to delete the old emergency alerts data. The notification_history table has this foreign key constraint, which makes trying to delete the template history for emergency alerts too slow to be feasible: ``` "notification_history_templates_history_fkey" FOREIGN KEY (template_id, template_version) REFERENCES templates_history(id, version) ``` This commit adds a composite index which matches the foreign key constraint.
1 parent 06a8490 commit a7cd961

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

migrations/.current-alembic-head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0507_n_history_service_id_index
1+
0508_n_history_templates_index
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Create Date: 2025-07-07 11:03:04.356066
3+
"""
4+
5+
from alembic import op
6+
7+
revision = '0508_n_history_templates_index'
8+
down_revision = '0507_n_history_service_id_index'
9+
10+
11+
def upgrade():
12+
with op.get_context().autocommit_block():
13+
op.execute(
14+
"CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_notification_history_template_composite on notification_history (template_id, template_version)"
15+
)
16+
17+
18+
def downgrade():
19+
with op.get_context().autocommit_block():
20+
op.execute(
21+
"DROP INDEX CONCURRENTLY IF EXISTS ix_notification_history_template_composite"
22+
)

0 commit comments

Comments
 (0)