feat: refs #6727 Added util logClean #2602

Merged
guillermo merged 10 commits from 6727-logClean into dev 2024-09-11 10:48:03 +00:00
3 changed files with 79 additions and 0 deletions
Showing only changes of commit 4880d1497f - Show all commits

View File

@ -0,0 +1,8 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `util`.`log_clean`
ON SCHEDULE EVERY 1 DAY
STARTS '2024-07-09 00:30:00.000'
ON COMPLETION PRESERVE
ENABLE
DO CALL util.log_clean$$
DELIMITER ;

View File

@ -0,0 +1,41 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`log_clean`()
BEGIN
/**
* Hace limpieza de los datos de las tablas log,
* dejando únicamente los días de retención configurados.
*/
DECLARE vSchemaName VARCHAR(65);
DECLARE vTableName VARCHAR(65);
DECLARE vRetentionDays INT;
DECLARE vDated DATE;
DECLARE vDone BOOL;
DECLARE vQueue CURSOR FOR
SELECT schemaName, tableName, retentionDays
FROM logClean
ORDER BY `order`;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN vQueue;
l: LOOP
SET vDone = FALSE;
FETCH vQueue INTO vSchemaName, vTableName, vRetentionDays;
SET vSchemaName = util.quoteIdentifier(vSchemaName);
SET vTableName = util.quoteIdentifier(vTableName);
SET vDated = VN_CURDATE() - INTERVAL vRetentionDays DAY;
IF vDone THEN
LEAVE l;
END IF;
CALL util.exec(CONCAT(
'DELETE FROM ', vSchemaName , '.', vTableName,
" WHERE creationDate < '", vDated, "'"
));
END LOOP;
CLOSE vQueue;
guillermo marked this conversation as resolved Outdated
Outdated
Review

Gastar EXECUTE INMEDIATE en lugar de util.exec ya que es una instrucción nativa.

Gastar `EXECUTE INMEDIATE` en lugar de `util.exec` ya que es una instrucción nativa.
END$$
DELIMITER ;

View File

@ -0,0 +1,30 @@
CREATE OR REPLACE TABLE `util`.`logClean` (
guillermo marked this conversation as resolved
Review

MultiConfig ya està consensuado? El nombre de la tabla se queda muy largo.

MultiConfig ya està consensuado? El nombre de la tabla se queda muy largo.
Review

Sí, está consensuado y puesto en la wiki, es más. ya está hecho el cambio en DEV

Sí, está consensuado y puesto en la wiki, es más. ya está hecho el cambio en DEV
`schemaName` varchar(64) NOT NULL,
`tableName` varchar(64) NOT NULL,
`retentionDays` int(11) NOT NULL,
`order` int(11) DEFAULT NULL,
PRIMARY KEY (`schemaName`,`tableName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
INSERT INTO `util`.`logClean` (`schemaName`, `tableName`, `retentionDays`, `order`)
VALUES
('account', 'roleLog', 'xxx', NULL),
('account', 'userLog', 'xxx', NULL),
('vn', 'entryLog', 'xxx', NULL),
('vn', 'clientLog', 'xxx', NULL),
('vn', 'itemLog', 'xxx', NULL),
('vn', 'shelvingLog', 'xxx', NULL),
('vn', 'workerLog', 'xxx', NULL),
('vn', 'deviceProductionLog', 'xxx', NULL),
('vn', 'zoneLog', 'xxx', NULL),
('vn', 'rateLog', 'xxx', NULL),
('vn', 'ticketLog', 'xxx', NULL),
('vn', 'agencyLog', 'xxx', NULL),
('vn', 'userLog', 'xxx', NULL),
('vn', 'routeLog', 'xxx', NULL),
('vn', 'claimLog', 'xxx', NULL),
('vn', 'supplierLog', 'xxx', NULL),
('vn', 'invoiceInLog', 'xxx', NULL),
('vn', 'travelLog', 'xxx', NULL),
('vn', 'packingSiteDeviceLog', 'xxx', NULL),
('vn', 'parkingLog', 'xxx', NULL);