From ff79c65cab6bfde66efc583adacb630060681e1a Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 21 Jun 2021 12:06:38 +0100 Subject: [PATCH] Move the indexes to be inline with the table. --- app/models.py | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/app/models.py b/app/models.py index 1584c38d5..586682b10 100644 --- a/app/models.py +++ b/app/models.py @@ -1472,7 +1472,20 @@ class Notification(db.Model): ['templates_history.id', 'templates_history.version'], ), UniqueConstraint('job_id', 'job_row_number', name='uq_notifications_job_row_number'), - {} + Index( + 'ix_notifications_notification_type_composite', + 'notification_type', + 'status', + 'created_at' + ), + Index('ix_notifications_service_created_at', 'service_id', 'created_at'), + Index( + "ix_notifications_service_id_composite", + 'service_id', + 'notification_type', + 'status', + 'created_at' + ) ) @property @@ -1727,7 +1740,13 @@ class NotificationHistory(db.Model, HistoryModel): ['template_id', 'template_version'], ['templates_history.id', 'templates_history.version'], ), - {} + Index( + 'ix_notification_history_service_id_composite', + 'service_id', + 'key_type', + 'notification_type', + 'created_at' + ) ) @classmethod @@ -1741,30 +1760,6 @@ class NotificationHistory(db.Model, HistoryModel): self.status = original.status -# Indexes for notification_history and notifications to improve performance of fetch queries. -Index( - 'ix_notification_history_service_id_composite', - NotificationHistory.service_id, - NotificationHistory.key_type, - NotificationHistory.notification_type, - NotificationHistory.created_at -) -Index( - 'ix_notifications_notification_type_composite', - Notification.notification_type, - Notification.status, - Notification.created_at -) -Index('ix_notifications_service_created_at', Notification.service_id, Notification.created_at) -Index( - "ix_notifications_service_id_composite", - Notification.service_id, - Notification.notification_type, - Notification.status, - Notification.created_at -) - - class ScheduledNotification(db.Model): __tablename__ = 'scheduled_notifications'