PC-1016 Delete snapshots > 30 days and not linked to report in

cleanup task
This commit is contained in:
Keir Nellyer 2016-10-29 14:38:16 +01:00
parent 09e5d13b96
commit 3dc441d61d
1 changed files with 6 additions and 0 deletions

View File

@ -58,6 +58,12 @@ DO BEGIN
LEFT JOIN snapshots ON reports.snapshotId = snapshots.id
WHERE reportResults.closedTime NOT BETWEEN NOW() - INTERVAL 30 DAY AND NOW();
-- DELETE SNAPSHOTS NOT LINKED TO REPORT AND OLDER THAN 30 DAYS
DELETE snapshots FROM snapshots
LEFT JOIN reports ON snapshots.id = reports.snapshotId
WHERE reports.id IS NULL
AND snapshots.created NOT BETWEEN NOW() - INTERVAL 30 DAY AND NOW();
-- DELETE ORPHANED SNAPSHOT MESSAGES
DELETE snapshotMessages FROM snapshotMessages
LEFT JOIN snapshotMessageMap ON snapshotMessages.id = snapshotMessageMap.messageId