salix/db/install/changes/only-local/00-nodeRecalc.sql

31 lines
673 B
MySQL
Raw Normal View History

/* Ejecutar en prod * /
/* DROP PROCEDURE IF EXISTS nst.nodeRecalc;
2019-03-12 14:04:09 +00:00
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeRecalc`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45))
BEGIN
CALL util.exec (sql_printf (
'UPDATE %t.%t d
JOIN (SELECT
node.id,
COUNT(parent.id) - 1 as depth,
cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons
FROM
%t.%t AS node,
%t.%t AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.id
ORDER BY node.lft) n ON n.id = d.id
SET d.`depth` = n.depth, d.sons = n.sons',
vScheme,
vTable,
vScheme,
vTable,
vScheme,
vTable
));
END$$
DELIMITER ;
*/