PC-1016 Schedule cleanup task for everyday at 00:00 CDT
This commit is contained in:
parent
4b3cadbb5a
commit
f0f01b74e8
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user