mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 08:16:19 -04:00
Stop deleting the mapping tables.
This commit is contained in:
@@ -24,13 +24,10 @@ from app import db, create_uuid
|
|||||||
from app.dao import days_ago
|
from app.dao import days_ago
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Notification,
|
Notification,
|
||||||
NotificationEmailReplyTo,
|
|
||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
ScheduledNotification,
|
ScheduledNotification,
|
||||||
Template,
|
Template,
|
||||||
TemplateHistory,
|
TemplateHistory,
|
||||||
EMAIL_TYPE,
|
|
||||||
SMS_TYPE,
|
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
@@ -41,8 +38,7 @@ from app.models import (
|
|||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
NOTIFICATION_TECHNICAL_FAILURE,
|
||||||
NOTIFICATION_TEMPORARY_FAILURE,
|
NOTIFICATION_TEMPORARY_FAILURE,
|
||||||
NOTIFICATION_PERMANENT_FAILURE,
|
NOTIFICATION_PERMANENT_FAILURE,
|
||||||
NOTIFICATION_SENT,
|
NOTIFICATION_SENT
|
||||||
NotificationSmsSender
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional
|
||||||
@@ -313,23 +309,6 @@ def _filter_query(query, filter_dict=None):
|
|||||||
@transactional
|
@transactional
|
||||||
def delete_notifications_created_more_than_a_week_ago_by_type(notification_type):
|
def delete_notifications_created_more_than_a_week_ago_by_type(notification_type):
|
||||||
seven_days_ago = date.today() - timedelta(days=7)
|
seven_days_ago = date.today() - timedelta(days=7)
|
||||||
|
|
||||||
# Following could be refactored when NotificationSmsReplyTo and NotificationLetterContact in models.py
|
|
||||||
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()
|
|
||||||
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(
|
|
||||||
notification_sender_mapping_table.notification_id.in_(subq)
|
|
||||||
).delete(synchronize_session='fetch')
|
|
||||||
|
|
||||||
deleted = db.session.query(Notification).filter(
|
deleted = db.session.query(Notification).filter(
|
||||||
func.date(Notification.created_at) < seven_days_ago,
|
func.date(Notification.created_at) < seven_days_ago,
|
||||||
Notification.notification_type == notification_type,
|
Notification.notification_type == notification_type,
|
||||||
|
|||||||
Reference in New Issue
Block a user