mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-06 09:08:24 -04:00
Merge branch 'cycle-notification_history-table' of github.com:alphagov/notifications-api into cycle-notification_history-table
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -22,7 +22,7 @@ END
|
||||
$$;
|
||||
|
||||
DROP TRIGGER IF EXISTS update_pivot on notification_history;
|
||||
-- may need to cancel the autovacuum
|
||||
-- Following may be blocked if running vacuum.
|
||||
-- select pg_cancel_backend(pid);
|
||||
CREATE TRIGGER update_pivot AFTER UPDATE OF notification_status, billable_units, updated_at, sent_by, sent_at ON notification_history
|
||||
FOR EACH ROW
|
||||
|
||||
23
migrations/versions/0321_notification_history_pivot.py
Normal file
23
migrations/versions/0321_notification_history_pivot.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0321_notification_history_pivot
|
||||
Revises: 0320_optimise_notifications
|
||||
Create Date: 2020-03-26 11:16:12.389524
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = '0321_notification_history_pivot'
|
||||
down_revision = '0320_optimise_notifications'
|
||||
environment = os.environ['NOTIFY_ENVIRONMENT']
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute('CREATE TABLE notification_history_pivot AS SELECT * FROM notification_history WHERE 1=2')
|
||||
op.execute('ALTER TABLE notification_history_pivot ADD PRIMARY KEY (id)')
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute('DROP TABLE notifications_history_pivot')
|
||||
Reference in New Issue
Block a user