This commit is contained in:
parent
fefc193ec0
commit
7a43ccaa36
|
@ -1,10 +1,6 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`clean`()
|
||||
BEGIN
|
||||
DECLARE vDateShort DATETIME;
|
||||
|
||||
SET vDateShort = util.VN_CURDATE() - INTERVAL 1 MONTH;
|
||||
|
||||
DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
|
||||
DELETE FROM cache.departure_limit WHERE Fecha < util.VN_CURDATE() - INTERVAL 1 MONTH;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -82,7 +82,7 @@ BEGIN
|
|||
DELETE c
|
||||
FROM claim c
|
||||
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||
WHERE cs.description = "Anulado"
|
||||
WHERE cs.description = 'Anulado'
|
||||
AND c.created < v2Months;
|
||||
|
||||
DELETE FROM expeditionTruck WHERE eta < v3Months;
|
||||
|
@ -94,69 +94,71 @@ BEGIN
|
|||
FROM travel t
|
||||
LEFT JOIN entry e ON e.travelFk = t.id
|
||||
JOIN travelThermograph th ON th.travelFk = t.id
|
||||
WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL;
|
||||
WHERE t.shipped < v3Months
|
||||
AND e.travelFk IS NULL;
|
||||
|
||||
SELECT dt.id INTO vTrashId
|
||||
FROM dmsType dt
|
||||
WHERE dt.code = 'trash';
|
||||
|
||||
UPDATE tThermographToDelete th
|
||||
JOIN dms d ON d.id = th.dmsFk
|
||||
JOIN dms d ON d.id = th.dmsFk
|
||||
SET d.dmsTypeFk = vTrashId;
|
||||
|
||||
DELETE th
|
||||
FROM tThermographToDelete tmp
|
||||
JOIN travelThermograph th ON th.id = tmp.id;
|
||||
JOIN travelThermograph th ON th.id = tmp.id;
|
||||
|
||||
DELETE t
|
||||
FROM travel t
|
||||
LEFT JOIN entry e ON e.travelFk = t.id
|
||||
WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL;
|
||||
LEFT JOIN entry e ON e.travelFk = t.id
|
||||
WHERE t.shipped < v3Months AND e.travelFk IS NULL;
|
||||
|
||||
UPDATE dms d
|
||||
JOIN dmsType dt ON dt.id = d.dmsTypeFk
|
||||
SET d.dmsTypeFk = vTrashId
|
||||
WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, util.VN_CURDATE());
|
||||
WHERE created < util.VN_CURDATE() - INTERVAL dt.monthToDelete MONTH;
|
||||
|
||||
-- borrar entradas sin compras
|
||||
CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete
|
||||
SELECT e.*
|
||||
FROM entry e
|
||||
LEFT JOIN buy b ON b.entryFk = e.id
|
||||
JOIN entryConfig ec ON e.id <> ec.defaultEntry
|
||||
WHERE e.dated < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND b.entryFK IS NULL;
|
||||
LEFT JOIN buy b ON b.entryFk = e.id
|
||||
JOIN entryConfig ec ON e.id <> ec.defaultEntry
|
||||
WHERE e.dated < v3Months
|
||||
AND b.entryFK IS NULL;
|
||||
|
||||
DELETE e
|
||||
FROM entry e
|
||||
JOIN tEntryToDelete tmp ON tmp.id = e.id;
|
||||
JOIN tEntryToDelete tmp ON tmp.id = e.id;
|
||||
|
||||
-- borrar de route registros menores a 4 años
|
||||
CREATE OR REPLACE TEMPORARY TABLE tRouteToDelete
|
||||
SELECT *
|
||||
FROM route r
|
||||
WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE());
|
||||
FROM route r
|
||||
WHERE created < v4Years;
|
||||
|
||||
UPDATE tRouteToDelete tmp
|
||||
JOIN dms d ON d.id = tmp.gestdocFk
|
||||
JOIN dms d ON d.id = tmp.gestdocFk
|
||||
SET d.dmsTypeFk = vTrashId;
|
||||
|
||||
DELETE r
|
||||
FROM tRouteToDelete tmp
|
||||
JOIN route r ON r.id = tmp.id;
|
||||
JOIN route r ON r.id = tmp.id;
|
||||
|
||||
-- borrar registros de dua y awb menores a 2 años
|
||||
CREATE OR REPLACE TEMPORARY TABLE tDuaToDelete
|
||||
SELECT *
|
||||
FROM dua
|
||||
WHERE operated < TIMESTAMPADD(YEAR,-2,CURDATE());
|
||||
WHERE operated < v2Years;
|
||||
|
||||
UPDATE tDuaToDelete tm
|
||||
JOIN dms d ON d.id = tm.gestdocFk
|
||||
UPDATE tDuaToDelete tm
|
||||
JOIN dms d ON d.id = tm.gestdocFk
|
||||
SET d.dmsTypeFk = vTrashId;
|
||||
|
||||
DELETE d
|
||||
FROM tDuaToDelete tmp
|
||||
JOIN dua d ON d.id = tmp.id;
|
||||
JOIN dua d ON d.id = tmp.id;
|
||||
|
||||
DELETE a
|
||||
FROM awb a
|
||||
|
@ -165,17 +167,16 @@ BEGIN
|
|||
AND t.id IS NULL;
|
||||
|
||||
-- Borra los registros de collection y ticketcollection
|
||||
DELETE FROM collection WHERE created < v2Months;
|
||||
DELETE FROM collection WHERE created < v2Months;
|
||||
DELETE FROM travelLog WHERE creationDate < v3Months;
|
||||
|
||||
CALL shelving_clean();
|
||||
|
||||
DELETE FROM chat WHERE dated < v5Years;
|
||||
DELETE tt FROM ticketTracking tt
|
||||
JOIN ticket t ON tt.ticketFk = t.id
|
||||
JOIN ticket t ON tt.ticketFk = t.id
|
||||
WHERE t.shipped <= v2Months;
|
||||
|
||||
-- Clean vn2008
|
||||
DELETE FROM mail WHERE creationDate < v2Months;
|
||||
DELETE FROM split WHERE dated < v18Months;
|
||||
DELETE FROM remittance WHERE dated < v18Months;
|
||||
|
|
Loading…
Reference in New Issue