salix/db/changes/10120-december/00-vnClean.sql

56 lines
2.0 KiB
MySQL
Raw Normal View History

2019-11-26 13:15:43 +00:00
DROP procedure IF EXISTS `vn`.`clean`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clean`()
BEGIN
DECLARE vDateShort DATETIME;
2019-11-27 10:57:09 +00:00
DECLARE vOneYearAgo DATE;
DECLARE vFourYearsAgo DATE;
2019-11-27 12:37:36 +00:00
DECLARE v18Month DATE;
DECLARE v26Month DATE;
DECLARE v3Month DATE;
2019-11-26 13:15:43 +00:00
SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
2019-11-27 10:57:09 +00:00
SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE());
SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,CURDATE());
2019-11-27 12:37:36 +00:00
SET v18Month = TIMESTAMPADD(MONTH, -18,CURDATE());
SET v26Month = TIMESTAMPADD(MONTH, -26,CURDATE());
SET v3Month = TIMESTAMPADD(MONTH, -3, CURDATE());
2019-11-26 13:15:43 +00:00
DELETE FROM `message` WHERE sendDate < vDateShort;
DELETE FROM messageInbox WHERE sendDate < vDateShort;
DELETE FROM messageInbox WHERE sendDate < vDateShort;
2019-11-27 10:57:09 +00:00
DELETE FROM workerTimeControl WHERE timed < vFourYearsAgo;
2019-11-26 13:15:43 +00:00
DELETE FROM itemShelving WHERE created < CURDATE() AND visible = 0;
DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,CURDATE());
DELETE FROM entryLog WHERE creationDate < vDateShort;
2019-11-27 12:37:36 +00:00
DELETE FROM expedition WHERE created < v26Month;
DELETE FROM sms WHERE created < v18Month;
DELETE FROM saleTracking WHERE created < vDateShort;
DELETE tobs FROM ticketObservation tobs
JOIN ticket t ON tobs.shipped = t.id WHERE t.shipped < vDateShort;
DELETE FROM sharingCart where ended < vDateShort;
DELETE FROM sharingClient where ended < vDateShort;
DELETE tw.* FROM ticketWeekly tw
LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL;
DELETE FROM claim WHERE ticketCreated < v18Month;
DELETE FROM message WHERE sendDate < vDateShort;
DELETE sc FROM saleChecked sc
JOIN sale s ON mc.Id_Movimiento = s.id WHERE s.created < vDateShort;
DELETE bm
FROM buyMark bm
JOIN buy b ON b.id = bm.id
JOIN entry e ON e.id = b.entryFk
JOIN travel t ON t.id = e.travelFk
WHERE t.landed <= vDateShort;
DELETE FROM stowaway WHERE created < v3Month;
2019-11-26 13:15:43 +00:00
CALL shelving_clean;
CALL ticketPackagingRecovery;
END$$
DELIMITER ;