Added the notification_to_sms_sender mapping table to the purge notifications query

This commit is contained in:
Rebecca Law
2017-10-30 15:17:01 +00:00
parent 0887910b1b
commit db6668eb61
3 changed files with 44 additions and 6 deletions

View File

@@ -33,6 +33,7 @@ from app.models import (
ServiceEmailReplyTo,
Template,
EMAIL_TYPE,
SMS_TYPE,
KEY_TYPE_NORMAL,
KEY_TYPE_TEST,
LETTER_TYPE,
@@ -374,17 +375,22 @@ def delete_notifications_created_more_than_a_week_ago_by_type(notification_type)
seven_days_ago = date.today() - timedelta(days=7)
# Following could be refactored when NotificationSmsReplyTo and NotificationLetterContact in models.py
if notification_type == EMAIL_TYPE:
if notification_type in [EMAIL_TYPE, SMS_TYPE]:
subq = db.session.query(Notification.id).filter(
func.date(Notification.created_at) < seven_days_ago,
Notification.notification_type == notification_type
).subquery()
deleted = db.session.query(
NotificationEmailReplyTo
if notification_type == EMAIL_TYPE:
notification_sender_mapping_table = NotificationEmailReplyTo
if notification_type == SMS_TYPE:
notification_sender_mapping_table = NotificationSmsSender
db.session.query(
notification_sender_mapping_table
).filter(
NotificationEmailReplyTo.notification_id.in_(subq)
notification_sender_mapping_table.notification_id.in_(subq)
).delete(synchronize_session='fetch')
deleted = db.session.query(Notification).filter(
func.date(Notification.created_at) < seven_days_ago,
Notification.notification_type == notification_type,

View File

@@ -10,7 +10,7 @@ from app.dao.dao_utils import (
transactional,
version_class
)
from app.dao.notifications_dao import get_financial_year
from app.dao.date_util import get_financial_year
from app.dao.service_sms_sender_dao import insert_service_sms_sender
from app.models import (
NotificationStatistics,