update procedures db
gitea/salix/1904delete_vn2008_references This commit looks good
Details
gitea/salix/1904delete_vn2008_references This commit looks good
Details
This commit is contained in:
parent
dcdd4473b1
commit
8f4e44aa37
|
@ -0,0 +1,123 @@
|
||||||
|
|
||||||
|
DROP procedure IF EXISTS `vn2008`.`clean`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `vn2008`.`clean`(IN `v_full` TINYINT(1))
|
||||||
|
proc: BEGIN
|
||||||
|
DECLARE v_date DATETIME;
|
||||||
|
DECLARE v_date18 DATETIME;
|
||||||
|
DECLARE v_date26 DATETIME;
|
||||||
|
DECLARE v_date8 DATE;
|
||||||
|
DECLARE v_date6 DATE;
|
||||||
|
DECLARE v_date3Month DATE;
|
||||||
|
DECLARE vDate2000 DATE;
|
||||||
|
DECLARE vRangeDeleteTicket INT;
|
||||||
|
DECLARE strtable varchar(15) DEFAULT NULL;
|
||||||
|
DECLARE done BIT DEFAULT 0;
|
||||||
|
|
||||||
|
SET v_date = TIMESTAMPADD(MONTH, -2, CURDATE());
|
||||||
|
SET v_date18 = TIMESTAMPADD(MONTH, -18,CURDATE());
|
||||||
|
SET v_date26 = TIMESTAMPADD(MONTH, -26,CURDATE());
|
||||||
|
SET v_date3Month = TIMESTAMPADD(MONTH, -3, CURDATE());
|
||||||
|
SET v_date8 = TIMESTAMPADD(DAY, -8,CURDATE());
|
||||||
|
SET v_date6 = TIMESTAMPADD(DAY, -6,CURDATE());
|
||||||
|
SET vRangeDeleteTicket = 60;
|
||||||
|
|
||||||
|
DELETE FROM cdr WHERE calldate < v_date;
|
||||||
|
DELETE FROM Monitoring WHERE ODBC_TIME < v_date;
|
||||||
|
DELETE FROM Conteo WHERE Fecha < v_date;
|
||||||
|
DELETE FROM XDiario WHERE FECHA < v_date3Month OR FECHA IS NULL;
|
||||||
|
DELETE FROM mail WHERE DATE_ODBC < v_date;
|
||||||
|
|
||||||
|
-- DELETE FROM Cajas WHERE CajaFecha < v_date18;
|
||||||
|
|
||||||
|
DELETE rr FROM Recibos_recorded rr JOIN Recibos r ON rr.Id_Recibos = r.Id WHERE r.Fechacobro < v_date;
|
||||||
|
|
||||||
|
SELECT MAX(idTickets_dits)
|
||||||
|
INTO @id
|
||||||
|
FROM Tickets_dits
|
||||||
|
WHERE ODBC_DATE < v_date;
|
||||||
|
DELETE FROM Tickets_dits WHERE idTickets_dits <= @id;
|
||||||
|
|
||||||
|
DELETE FROM expeditions_deleted WHERE odbc_date < v_date26;
|
||||||
|
DELETE FROM Entradas_dits WHERE ODBC_DATE < v_date18;
|
||||||
|
DELETE FROM log_articles WHERE ODBC_DATE < v_date;
|
||||||
|
DELETE FROM Splits WHERE Fecha < v_date18;
|
||||||
|
DELETE ts FROM Tickets_stack ts JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date;
|
||||||
|
DELETE tobs FROM movement_label tobs JOIN Movimientos m ON tobs.Id_Movimiento = m.Id_Movimiento
|
||||||
|
JOIN Tickets t ON m.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date;
|
||||||
|
DELETE FROM chat WHERE odbc_date < v_date;
|
||||||
|
DELETE FROM Extractos WHERE Fecha < v_date;
|
||||||
|
DELETE FROM Remesas WHERE `Fecha Remesa` < v_date18;
|
||||||
|
DELETE FROM Stockcontrol WHERE Datestart < v_date18;
|
||||||
|
-- DELETE FROM reference_rate WHERE date < v_date18;
|
||||||
|
DELETE FROM hedera.`order` WHERE date_send < v_date18;
|
||||||
|
-- DELETE FROM Ordenes WHERE odbc_date < v_date18; JGF 2018-12-21 Si estan en un turno no hay que borrarlas.
|
||||||
|
|
||||||
|
SELECT MAX(inter_id)
|
||||||
|
INTO @id
|
||||||
|
FROM vncontrol.inter
|
||||||
|
WHERE odbc_date < v_date18;
|
||||||
|
DELETE FROM vncontrol.inter WHERE inter_id <= @id;
|
||||||
|
|
||||||
|
DELETE FROM Entradas_dits WHERE ODBC_DATE < v_date;
|
||||||
|
DELETE FROM cyc_declaration WHERE Fecha < v_date18;
|
||||||
|
DELETE FROM travel_reserve WHERE odbc_date < v_date;
|
||||||
|
-- DELETE FROM syslog.systemevents WHERE odbc_date < v_date8;
|
||||||
|
|
||||||
|
DELETE FROM cache.departure_limit WHERE Fecha < TIMESTAMPADD(MONTH,-1,CURDATE());
|
||||||
|
DELETE co
|
||||||
|
FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra
|
||||||
|
JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
|
||||||
|
JOIN travel t ON t.id = e.travel_id
|
||||||
|
WHERE t.landing <= v_date;
|
||||||
|
|
||||||
|
DELETE FROM vn2008.scan WHERE odbc_date < v_date6 AND id <> 1;
|
||||||
|
|
||||||
|
SET vDate2000 = TIMESTAMPADD(YEAR, 2000 - YEAR(CURDATE()), CURDATE());
|
||||||
|
|
||||||
|
IF v_full
|
||||||
|
THEN
|
||||||
|
DELETE t FROM Tickets t
|
||||||
|
LEFT JOIN Tickets_turno tt ON tt.Id_Ticket = t.Id_Ticket
|
||||||
|
WHERE Fecha NOT IN ('2000-01-01','2000-01-02')
|
||||||
|
AND YEAR(Fecha) = 2000
|
||||||
|
AND ABS(DATEDIFF(Fecha,vDate2000)) > vRangeDeleteTicket
|
||||||
|
AND tt.Id_Ticket IS NULL;
|
||||||
|
|
||||||
|
DELETE e.* FROM Entradas e
|
||||||
|
LEFT JOIN recibida_entrada re ON e.Id_Entrada = re.Id_Entrada
|
||||||
|
WHERE travel_id IS NULL
|
||||||
|
AND re.Id_Entrada IS NULL;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Tickets Nulos PAK 11/10/2016
|
||||||
|
|
||||||
|
UPDATE vn2008.Tickets
|
||||||
|
SET empresa_id = 965
|
||||||
|
WHERE Id_Cliente = 31
|
||||||
|
AND empresa_id != 965;
|
||||||
|
|
||||||
|
-- Equipos duplicados
|
||||||
|
|
||||||
|
DELETE w.*
|
||||||
|
FROM vn2008.workerTeam w
|
||||||
|
JOIN (SELECT id, team, workerFk, COUNT(*) - 1 as duplicated
|
||||||
|
FROM vn.workerTeam
|
||||||
|
GROUP BY team,workerFk
|
||||||
|
HAVING duplicated
|
||||||
|
) d ON d.team = w.team AND d.workerFk = w.user AND d.id != w.id;
|
||||||
|
|
||||||
|
-- CAP 29/10/2018 Mantenimiento tabla Movimientos_componentes
|
||||||
|
|
||||||
|
DELETE mc
|
||||||
|
FROM vn2008.Movimientos_componentes mc
|
||||||
|
JOIN vn2008.Movimientos mv
|
||||||
|
ON mv.Id_Movimiento=mc.Id_Movimiento
|
||||||
|
JOIN vn2008.Tickets t
|
||||||
|
ON t.Id_Ticket= mv.Id_Ticket
|
||||||
|
WHERE t.Fecha<v_date18;
|
||||||
|
END$$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
|
@ -6,13 +6,17 @@ CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clean`()
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vDateShort DATETIME;
|
DECLARE vDateShort DATETIME;
|
||||||
DECLARE vOneYearAgo DATE;
|
DECLARE vOneYearAgo DATE;
|
||||||
DECLARE vTwoYearsAgo DATE;
|
|
||||||
DECLARE vFourYearsAgo DATE;
|
DECLARE vFourYearsAgo DATE;
|
||||||
|
DECLARE v18Month DATE;
|
||||||
|
DECLARE v26Month DATE;
|
||||||
|
DECLARE v3Month DATE;
|
||||||
|
|
||||||
SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
|
SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
|
||||||
SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE());
|
SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE());
|
||||||
SET vTwoYearsAgo = TIMESTAMPADD(YEAR,-2,CURDATE());
|
|
||||||
SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,CURDATE());
|
SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,CURDATE());
|
||||||
|
SET v18Month = TIMESTAMPADD(MONTH, -18,CURDATE());
|
||||||
|
SET v26Month = TIMESTAMPADD(MONTH, -26,CURDATE());
|
||||||
|
SET v3Month = TIMESTAMPADD(MONTH, -3, CURDATE());
|
||||||
|
|
||||||
DELETE FROM `message` WHERE sendDate < vDateShort;
|
DELETE FROM `message` WHERE sendDate < vDateShort;
|
||||||
DELETE FROM messageInbox WHERE sendDate < vDateShort;
|
DELETE FROM messageInbox WHERE sendDate < vDateShort;
|
||||||
|
@ -21,7 +25,26 @@ BEGIN
|
||||||
DELETE FROM itemShelving WHERE created < CURDATE() AND visible = 0;
|
DELETE FROM itemShelving WHERE created < CURDATE() AND visible = 0;
|
||||||
DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,CURDATE());
|
DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,CURDATE());
|
||||||
DELETE FROM entryLog WHERE creationDate < vDateShort;
|
DELETE FROM entryLog WHERE creationDate < vDateShort;
|
||||||
|
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;
|
||||||
CALL shelving_clean;
|
CALL shelving_clean;
|
||||||
|
|
||||||
CALL ticketPackagingRecovery;
|
CALL ticketPackagingRecovery;
|
||||||
|
|
Loading…
Reference in New Issue