This commit is contained in:
parent
c330e8c715
commit
c0668d054f
|
@ -7,8 +7,8 @@ SET foreign_key_checks = 0;
|
||||||
|
|
||||||
-- XXX: vn-database
|
-- XXX: vn-database
|
||||||
|
|
||||||
INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled, daysKeepDeprecatedObjects)
|
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, 60);
|
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`)
|
INSERT INTO util.binlogQueue (code,logName, `position`)
|
||||||
VALUES ('mylogger', 'bin.000001', 4);
|
VALUES ('mylogger', 'bin.000001', 4);
|
||||||
|
|
|
@ -6,11 +6,9 @@ BEGIN
|
||||||
* Elimina objetos deprecados de la base de datos
|
* Elimina objetos deprecados de la base de datos
|
||||||
*/
|
*/
|
||||||
DECLARE vQuery TEXT;
|
DECLARE vQuery TEXT;
|
||||||
DECLARE vDated DATE
|
DECLARE vDated DATE;
|
||||||
DEFAULT (
|
DECLARE vDateRegex VARCHAR(255);
|
||||||
SELECT VN_CURDATE() - INTERVAL daysKeepDeprecatedObjects DAY
|
DECLARE vMarkRegex VARCHAR(255);
|
||||||
FROM config
|
|
||||||
);
|
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
|
|
||||||
DECLARE vObjects CURSOR FOR
|
DECLARE vObjects CURSOR FOR
|
||||||
|
@ -21,8 +19,8 @@ BEGIN
|
||||||
JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA
|
JOIN information_schema.STATISTICS s ON s.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||||
AND s.TABLE_NAME = c.TABLE_NAME
|
AND s.TABLE_NAME = c.TABLE_NAME
|
||||||
AND s.COLUMN_NAME = c.COLUMN_NAME
|
AND s.COLUMN_NAME = c.COLUMN_NAME
|
||||||
WHERE c.COLUMN_NAME LIKE '%\_\_'
|
WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated
|
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated
|
||||||
AND v.TABLE_NAME IS NULL
|
AND v.TABLE_NAME IS NULL
|
||||||
AND s.INDEX_NAME = 'PRIMARY'
|
AND s.INDEX_NAME = 'PRIMARY'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
@ -33,8 +31,8 @@ BEGIN
|
||||||
JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||||
AND kcu.TABLE_NAME = c.TABLE_NAME
|
AND kcu.TABLE_NAME = c.TABLE_NAME
|
||||||
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
||||||
WHERE c.COLUMN_NAME LIKE '%\_\_'
|
WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated
|
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated
|
||||||
AND v.TABLE_NAME IS NULL
|
AND v.TABLE_NAME IS NULL
|
||||||
AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL
|
AND kcu.REFERENCED_COLUMN_NAME IS NOT NULL
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
@ -45,20 +43,20 @@ BEGIN
|
||||||
LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
LEFT JOIN information_schema.KEY_COLUMN_USAGE kcu ON kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
|
||||||
AND kcu.TABLE_NAME = c.TABLE_NAME
|
AND kcu.TABLE_NAME = c.TABLE_NAME
|
||||||
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
AND kcu.COLUMN_NAME = c.COLUMN_NAME
|
||||||
WHERE c.COLUMN_NAME LIKE '%\_\_'
|
WHERE c.COLUMN_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||||
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated
|
AND REGEXP_SUBSTR(c.COLUMN_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated
|
||||||
AND v.TABLE_NAME IS NULL
|
AND v.TABLE_NAME IS NULL
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';')
|
SELECT CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';')
|
||||||
FROM information_schema.TABLES
|
FROM information_schema.TABLES
|
||||||
WHERE TABLE_NAME LIKE '%\_\_'
|
WHERE TABLE_NAME REGEXP vMarkRegex COLLATE utf8mb3_unicode_ci
|
||||||
AND REGEXP_SUBSTR(TABLE_COMMENT, '[0-9]{4}-[0-9]{2}-[0-9]{2}') < vDated;
|
AND REGEXP_SUBSTR(TABLE_COMMENT, vDateRegex COLLATE utf8mb3_unicode_ci) < vDated;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
BEGIN
|
BEGIN
|
||||||
CALL mail_insert(
|
CALL vn.mail_insert(
|
||||||
'cau@verdnatura.es',
|
'cau@verdnatura.es',
|
||||||
NULL,
|
NULL,
|
||||||
'Error en la eliminación automática de objetos deprecados',
|
'Error en la eliminación automática de objetos deprecados',
|
||||||
|
@ -68,8 +66,16 @@ BEGIN
|
||||||
RESIGNAL;
|
RESIGNAL;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
IF vDated IS NULL THEN
|
SELECT dateRegex,
|
||||||
CALL throw('Variable config not set');
|
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;
|
END IF;
|
||||||
|
|
||||||
OPEN vObjects;
|
OPEN vObjects;
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
ALTER TABLE util.config
|
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.';
|
ADD daysKeepDeprecatedObjects int(11) unsigned NULL COMMENT 'Número de días que se mantendrán los objetos deprecados.';
|
||||||
|
|
||||||
UPDATE IGNORE util.config
|
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`
|
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 `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15 refs #6738',
|
||||||
|
|
Loading…
Reference in New Issue