feat: refs #6727 Added util logClean
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-06-18 08:40:33 +02:00
parent a84badff87
commit 4880d1497f
3 changed files with 79 additions and 0 deletions

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;
END$$
DELIMITER ;

View File

@ -0,0 +1,30 @@
CREATE OR REPLACE TABLE `util`.`logClean` (
`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);