PC-1016 Schedule cleanup task for everyday at 00:00 CDT

This commit is contained in:
Keir Nellyer 2016-10-28 18:13:20 +01:00
parent 4b3cadbb5a
commit f0f01b74e8

View File

@ -35,12 +35,17 @@ FOREIGN KEY (messageId) REFERENCES snapshotMessages (id) ON DELETE CASCADE;
-- CREATE CLEANUP TASK
DELIMITER //
-- CREATE EVENT TO RUN EVERY DAY AT 00:00
CREATE EVENT `report_cleanup`
ON SCHEDULE EVERY 1 MONTH
ON SCHEDULE
EVERY 1 DAY
-- FORCE TASK TO RUN AT 00:00 DAILY
STARTS (TIMESTAMP(CURRENT_DATE) + INTERVAL 1 DAY)
ON COMPLETION PRESERVE
COMMENT 'Cleans up old report and snapshot data.'
DO BEGIN
-- DELETE REPORTS (AND ASSOCIATED SNAPSHOT IF ANY) CLOSED > 30 DAYS AGO
DELETE reports, snapshots FROM reports, snapshots
DELETE reports, snapshots FROM reports
LEFT JOIN reportResults ON reports.id = reportResults.reportId
LEFT JOIN snapshots ON reports.snapshotId = snapshots.id
WHERE reportResults.closedTime NOT BETWEEN NOW() - INTERVAL 30 DAY AND NOW();