mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
WIP
This commit is contained in:
@@ -908,17 +908,28 @@ def cycle_notification_history_table(limit_row_count):
|
|||||||
# This relies on the notification_history_pivot table being created
|
# This relies on the notification_history_pivot table being created
|
||||||
# and a trigger on notification_history has been created
|
# and a trigger on notification_history has been created
|
||||||
# what limit should we use here
|
# what limit should we use here
|
||||||
insert_sql = """
|
|
||||||
INSERT INTO notification_history_pivot
|
populate_temp_table = """
|
||||||
SELECT *
|
SELECT id
|
||||||
FROM notification_history h
|
INTO nh_temp
|
||||||
WHERE not exists (select id from notification_history_pivot where id = h.id)
|
FROM notification_history
|
||||||
LIMIT :limit_row_count;
|
|
||||||
"""
|
"""
|
||||||
print('start population of notification_history_pivot table')
|
rows_to_insert = "SELECT COUNT(*) FROM nh_temp"
|
||||||
row_count = -1
|
|
||||||
while row_count != 0:
|
delete_temp_rows = """
|
||||||
r = db.session.execute(insert_sql, {"limit_row_count": limit_row_count})
|
DELETE FROM nh_temp t
|
||||||
row_count = r.rowcount
|
USING notification_history_pivot p
|
||||||
db.session.commit()
|
WHERE t.id = p.id
|
||||||
print('end population of notification_history_pivot table')
|
"""
|
||||||
|
rows_remaining = "SELECT COUNT(*) FROM nh_temp"
|
||||||
|
# In each function call, using same database connection as used for the above SQL
|
||||||
|
# (needs to be in a transaction; this can be inside a stored function or in a transaction from the code)
|
||||||
|
|
||||||
|
insert_sql = """
|
||||||
|
INSERT INTO notification_history_pivot
|
||||||
|
SELECT n.*
|
||||||
|
FROM notification_history n,
|
||||||
|
nh_temp t
|
||||||
|
WHERE n.id = t.id
|
||||||
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user