Merge branch 'main' of https://github.com/GSA/notifications-api into notify-260

This commit is contained in:
Kenneth Kehl
2023-05-30 11:47:36 -07:00
38 changed files with 305 additions and 544 deletions

View File

@@ -271,6 +271,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