mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
notify-233: delete notifications from notifications table after they are successfully sent
This commit is contained in:
@@ -269,6 +269,37 @@ def _filter_query(query, filter_dict=None):
|
||||
return query
|
||||
|
||||
|
||||
@autocommit
|
||||
def insert_notification_history_delete_notifications_by_id(
|
||||
notification_id
|
||||
):
|
||||
"""
|
||||
Deletes one notification after it has run successfully and moves it to the notification_history
|
||||
table.
|
||||
"""
|
||||
input_params = {
|
||||
"notification_id": notification_id
|
||||
}
|
||||
# Insert into NotificationHistory if the row already exists do nothing.
|
||||
insert_query = """
|
||||
insert into notification_history
|
||||
SELECT id, job_id, job_row_number, service_id, template_id, template_version, api_key_id,
|
||||
key_type, notification_type, created_at, sent_at, sent_by, updated_at, reference, billable_units,
|
||||
client_reference, international, phone_prefix, rate_multiplier, notification_status,
|
||||
created_by_id, document_download_count
|
||||
from NOTIFICATIONS WHERE id= :notification_id
|
||||
ON CONFLICT ON CONSTRAINT notification_history_pkey
|
||||
DO NOTHING
|
||||
"""
|
||||
delete_query = """
|
||||
DELETE FROM notifications
|
||||
where id= :notification_id
|
||||
"""
|
||||
|
||||
db.session.execute(insert_query, input_params)
|
||||
db.session.execute(delete_query, input_params)
|
||||
|
||||
|
||||
@autocommit
|
||||
def insert_notification_history_delete_notifications(
|
||||
notification_type, service_id, timestamp_to_delete_backwards_from, qry_limit=50000
|
||||
|
||||
Reference in New Issue
Block a user