2024-06-18 06:40:33 +00:00
|
|
|
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);
|
2024-07-19 07:29:15 +00:00
|
|
|
DECLARE vSchemaNameQuoted VARCHAR(65);
|
2024-06-18 06:40:33 +00:00
|
|
|
DECLARE vTableName VARCHAR(65);
|
2024-07-19 07:29:15 +00:00
|
|
|
DECLARE vTableNameQuoted VARCHAR(65);
|
2024-06-18 06:40:33 +00:00
|
|
|
DECLARE vRetentionDays INT;
|
2024-07-19 06:58:51 +00:00
|
|
|
DECLARE vStarted DATETIME;
|
2024-06-18 06:40:33 +00:00
|
|
|
DECLARE vDated DATE;
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
|
|
|
|
DECLARE vQueue CURSOR FOR
|
|
|
|
SELECT schemaName, tableName, retentionDays
|
2024-07-19 06:27:39 +00:00
|
|
|
FROM logCleanMultiConfig
|
2024-06-18 06:40:33 +00:00
|
|
|
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;
|
|
|
|
|
2024-07-19 06:58:51 +00:00
|
|
|
IF vDone THEN
|
|
|
|
LEAVE l;
|
|
|
|
END IF;
|
2024-07-19 06:27:39 +00:00
|
|
|
|
2024-07-19 06:58:51 +00:00
|
|
|
IF vRetentionDays THEN
|
2024-07-19 07:29:42 +00:00
|
|
|
SET vStarted = VN_NOW();
|
|
|
|
SET vSchemaNameQuoted = quoteIdentifier(vSchemaName);
|
|
|
|
SET vTableNameQuoted = quoteIdentifier(vTableName);
|
2024-07-19 06:27:39 +00:00
|
|
|
SET vDated = VN_CURDATE() - INTERVAL vRetentionDays DAY;
|
|
|
|
|
2024-07-19 07:29:15 +00:00
|
|
|
EXECUTE IMMEDIATE CONCAT(
|
|
|
|
'DELETE FROM ', vSchemaNameQuoted,
|
|
|
|
'.', vTableNameQuoted,
|
2024-07-19 06:27:39 +00:00
|
|
|
" WHERE creationDate < '", vDated, "'"
|
2024-07-19 07:29:15 +00:00
|
|
|
);
|
2024-07-19 06:27:39 +00:00
|
|
|
|
|
|
|
UPDATE logCleanMultiConfig
|
2024-07-19 06:58:51 +00:00
|
|
|
SET `started` = vStarted,
|
|
|
|
`finished` = VN_NOW()
|
2024-07-19 06:27:39 +00:00
|
|
|
WHERE schemaName = vSchemaName
|
|
|
|
AND tableName = vTableName;
|
|
|
|
END IF;
|
2024-06-18 06:40:33 +00:00
|
|
|
END LOOP;
|
|
|
|
CLOSE vQueue;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|