Merge branch 'cycle-notification_history-table' of github.com:alphagov/notifications-api into cycle-notification_history-table

This commit is contained in:
Rebecca Law
2020-05-05 17:23:23 +01:00
3 changed files with 34 additions and 1 deletions

View File

@@ -372,6 +372,14 @@ def insert_notification_history_delete_notifications(
ON CONFLICT ON CONSTRAINT notification_history_pkey
DO NOTHING
"""
# Insert data into the pivot table as well. Only needed while we are trying to cycle the history table.
insert_pivot_query = """
insert into notification_history_pivot
SELECT * from NOTIFICATION_ARCHIVE
ON CONFLICT ON CONSTRAINT notification_history_pivot_pkey
DO NOTHING
"""
delete_query = """
DELETE FROM notifications
where id in (select id from NOTIFICATION_ARCHIVE)
@@ -390,6 +398,8 @@ def insert_notification_history_delete_notifications(
db.session.execute(insert_query)
db.session.execute(insert_pivot_query)
db.session.execute(delete_query)
db.session.execute("DROP TABLE NOTIFICATION_ARCHIVE")