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, daysKeepDeprecatedObjects)
|
||||
VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, 60);
|
||||
INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, dateRegex, deprecatedMarkRegex, daysKeepDeprecatedObjects)
|
||||
VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE, '[0-9]{4}-[0-9]{2}-[0-9]{2}', '__$', 60);
|
||||
|
||||
INSERT INTO util.binlogQueue (code,logName, `position`)
|
||||
VALUES ('mylogger', 'bin.000001', 4);
|
||||
|
|
|
@ -6,11 +6,9 @@ BEGIN
|
|||
* Elimina objetos deprecados de la base de datos
|
||||
*/
|
||||
DECLARE vQuery TEXT;
|
||||
DECLARE vDated DATE
|
||||
DEFAULT (
|
||||
SELECT VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY
|
||||
FROM config
|
||||
);
|
||||
DECLARE vDated DATE;
|
||||
DECLARE vDateRegex VARCHAR(255);
|
||||
DECLARE vMarkRegex VARCHAR(255);
|
||||
DECLARE vDone BOOL;
|
||||
|
||||
DECLARE vObjects CURSOR FOR
|
||||
|
@ -21,8 +19,8 @@ BEGIN
|
|||
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
|
||||
WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated
|
||||
AND v.TABLE_NAME IS NULL
|
||||
AND s.INDEX_NAME = 'PRIMARY'
|
||||
UNION ALL
|
||||
|
@ -33,8 +31,8 @@ BEGIN
|
|||
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
|
||||
WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated
|
||||
AND v.TABLE_NAME IS NULL
|
||||
AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL
|
||||
UNION ALL
|
||||
|
@ -45,20 +43,20 @@ BEGIN
|
|||
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
|
||||
WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < 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;
|
||||
WHERE TABLE_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||
AND REGEXP_SUBSTR(TABLE_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
CALL mail_insert(
|
||||
CALL vn.mail_insert(
|
||||
'cau@verdnatura.es',
|
||||
NULL,
|
||||
'Error en la eliminación automática de objetos deprecados',
|
||||
|
@ -68,8 +66,16 @@ BEGIN
|
|||
RESIGNAL;
|
||||
END;
|
||||
|
||||
IF vDated IS NULL THEN
|
||||
CALL throw('Variable config not set');
|
||||
SELECT dateRegex,
|
||||
deprecatedMarkRegex,
|
||||
VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY
|
||||
INTO vDateRegex,
|
||||
vMarkRegex,
|
||||
vDated
|
||||
FROM config;
|
||||
|
||||
IF vDateRegex IS NULL OR vMarkRegex IS NULL OR vDated IS NULL THEN
|
||||
CALL throw('Some config parameters are not set');
|
||||
END IF;
|
||||
|
||||
OPEN vObjects;
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
ALTER TABLE util.config
|
||||
ADD COLUMN dateRegex varchar(255) NULL COMMENT 'Expresión regular para obtener las fechas.',
|
||||
ADD deprecatedMarkRegex varchar(255) NULL COMMENT 'Expresión regular para obtener los objetos deprecados.',
|
||||
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;
|
||||
SET dateRegex = '[0-9]{4}-[0-9]{2}-[0-9]{2}',
|
||||
deprecatedMarkRegex = '__$',
|
||||
daysKeepDeprecatedObjects = 60;
|
||||
|
||||
ALTER TABLE IF EXISTS `vn`.`payrollWorker`
|
||||
MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||
|
|
Loading…
Reference in New Issue