8032-devToTest_2440 #3009
|
@ -7,8 +7,8 @@ SET foreign_key_checks = 0;
|
|||
|
||||
-- XXX: vn-database
|
||||
|
||||
INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled)
|
||||
VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE);
|
||||
INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, daysKeepDeprecatedObjects)
|
||||
VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, 60);
|
||||
|
||||
INSERT INTO util.binlogQueue (code,logName, `position`)
|
||||
VALUES ('mylogger', 'bin.000001', 4);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `util`.`deleteDeprecatedObjects`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2024-06-09 00:01:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO CALL deleteDeprecatedObjects$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,88 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`deleteDeprecatedObjects`()
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Elimina objetos deprecados de la base de datos
|
||||
*/
|
||||
DECLARE vQuery TEXT;
|
||||
DECLARE vDated DATE
|
||||
DEFAULT (
|
||||
SELECT CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY
|
||||
FROM config
|
||||
);
|
||||
DECLARE vDone BOOL;
|
||||
|
||||
DECLARE vObjects CURSOR FOR
|
||||
SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP PRIMARY KEY;')
|
||||
FROM information_schema.`COLUMNS` c
|
||||
LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||
AND v.TABLE_NAME = c.TABLE_NAME
|
||||
JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||
AND s.TABLE_NAME = c.TABLE_NAME
|
||||
AND s.COLUMN_NAME = c.COLUMN_NAME
|
||||
WHERE c.COLUMN_NAME LIKE '%\_\_'
|
||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated
|
||||
AND v.TABLE_NAME IS NULL
|
||||
AND s.INDEX_NAME = 'PRIMARY'
|
||||
UNION ALL
|
||||
SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP FOREIGN KEY ', kcu.CONSTRAINT_NAME, ';')
|
||||
FROM information_schema.`COLUMNS` c
|
||||
LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||
AND v.TABLE_NAME = c.TABLE_NAME
|
||||
JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||
AND kcu.TABLE_NAME = c.TABLE_NAME
|
||||
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
||||
WHERE c.COLUMN_NAME LIKE '%\_\_'
|
||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated
|
||||
AND v.TABLE_NAME IS NULL
|
||||
AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT CONCAT('ALTER TABLE ', c.TABLE_SCHEMA, '.', c.TABLE_NAME, ' DROP COLUMN ', c.COLUMN_NAME, ';')
|
||||
FROM information_schema.`COLUMNS` c
|
||||
LEFT JOIN information_schema.`VIEWS` v ON v.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||
AND v.TABLE_NAME = c.TABLE_NAME
|
||||
LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||
AND kcu.TABLE_NAME = c.TABLE_NAME
|
||||
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
||||
WHERE c.COLUMN_NAME LIKE '%\_\_'
|
||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated
|
||||
AND v.TABLE_NAME IS NULL
|
||||
UNION ALL
|
||||
SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';')
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_NAME LIKE '%\_\_'
|
||||
AND REGEXP_SUBSTR(TABLE_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
CALL mail_insert(
|
||||
'cau@verdnatura.es',
|
||||
NULL,
|
||||
'Error en la eliminación automática de objetos deprecados',
|
||||
CONCAT('<pre>', vQuery, '</pre>',
|
||||
'<p>Revisa la tabla <strong>util.eventLog</strong> para más detalles.</p>')
|
||||
);
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
IF vDated IS NULL THEN
|
||||
CALL throw('Variable config not set');
|
||||
END IF;
|
||||
|
||||
OPEN vObjects;
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vObjects INTO vQuery;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
CALL `exec`(vQuery);
|
||||
END LOOP;
|
||||
CLOSE vObjects;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,22 @@
|
|||
ALTER TABLE util.config
|
||||
ADD daysKeepDeprecatedObjects int(11) unsigned NULL COMMENT 'Número de días que se mantendrán los objetos deprecados.';
|
||||
|
||||
UPDATE IGNORE util.config
|
||||
SET daysKeepDeprecatedObjects = 60;
|
||||
|
||||
ALTER TABLE IF EXISTS `vn`.`payrollWorker`
|
||||
MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `codpuesto__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `codcontrato__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `FAntiguedad__` date NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `grupotarifa__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `codcategoria__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `ContratoTemporal__` tinyint(1) NOT NULL DEFAULT 0 COMMENT '@deprecated 2024-03-15 refs #6738';
|
||||
|
||||
ALTER TABLE IF EXISTS `vn`.`payrollWorkCenter`
|
||||
MODIFY COLUMN IF EXISTS `Centro__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `nss_cotizacion__` varchar(15) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `domicilio__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `poblacion__` varchar(45) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `cp__` varchar(5) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
MODIFY COLUMN IF EXISTS `empresa_id__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738';
|
Loading…
Reference in New Issue