grid adapt step by step

parent aa100083
......@@ -15,58 +15,32 @@ ALTER TABLE `grid` ADD `color` varchar(7) NULL;
-- Foreign key stu_picto(id_child_grid) <- grid(id)
ALTER TABLE stu_picto ADD FOREIGN KEY(id_child_grid) REFERENCES grid(id) ON DELETE SET NULL;
DELIMITER $$
DROP PROCEDURE IF EXISTS new_grid_system $$
CREATE PROCEDURE new_grid_system()
BEGIN
-- Cursor para recorrer los pictos de escenas sin categorias
DECLARE cursor_stu_picto_free_category CURSOR FOR
SELECT id, id_stu, attributes FROM pictodb.stu_picto
WHERE attributes->>"$.free_category_coord_x" != 'null' AND attributes->>"$.free_category_coord_y" != 'null';
-- Cursor para recorrer los pictos de escenas con categorias y que se encuentran en la escena principal
DECLARE cursor_stu_picto_categories_parent CURSOR FOR
SELECT id, id_stu, attributes FROM pictodb.stu_picto
WHERE attributes->>"$.coord_x" != 'null' AND attributes->>"$.coord_y" != 'null' AND attributes->>"$.id_cat" = 'null';
-- Cursor para recorrer los pictos de escenas con categorias y que son hijos de alguna categoria
DECLARE cursor_stu_picto_categories_child CURSOR FOR SELECT id, id_stu, attributes FROM pictodb.stu_picto
SELECT id, id_stu, attributes FROM pictodb.stu_picto
WHERE attributes->>"$.coord_x" != 'null' AND attributes->>"$.coord_y" != 'null' AND attributes->>"$.id_cat" != 'null';
DECLARE done INT DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_stu_picto_free_category;
read_loop: LOOP
FETCH cursor_stu_picto_free_category INTO _id_stu_picto, _id_stu, _attributes;
-- Control para la finalizacion del bucle
IF done THEN
LEAVE read_loop;
END IF;
-- Pasa las coordenadas libres a coord_x y coord_y
-- ESCENAS SIN CATEGORIAS
-- Pasa los pictos de escenas sin categorias al nuevo sistema
UPDATE stu_picto
SET
`attributes` = JSON_REPLACE(`attributes`, '$.coord_x', _free_category_coord_x),
`attributes` = JSON_REPLACE(`attributes`, '$.coord_y', _free_category_coord_y)
WHERE id = _id_stu_picto;
`attributes` = JSON_REPLACE(`attributes`, '$.coord_x', attributes->'$.free_category_coord_x'),
`attributes` = JSON_REPLACE(`attributes`, '$.coord_y', attributes->'$.free_category_coord_y')
WHERE attributes->>"$.free_category_coord_x" != 'null' AND attributes->>"$.free_category_coord_y" != 'null';
-- ESCENAS CON CATEGORIAS
-- Pictos principales de las escenas, sólo limpia su JSON
UPDATE stu_picto
SET
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_x'),
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_y'),
`attributes` = JSON_REMOVE(`attributes`, '$.id_cat')
WHERE id = _id_stu_picto;
WHERE attributes->>"$.coord_x" != 'null' AND attributes->>"$.coord_y" != 'null' AND attributes->>"$.id_cat" = 'null';
-- Pictos hijos de las escenas
DELETE FROM stu_picto WHERE attributes->>"$.id_cat" != 'null';
END LOOP;
CLOSE cursor_stu_picto_free_category;
SET done = FALSE;
END $$
DELIMITER ;
CALL new_grid_system();
-- LIMPIA EL JSON DE TODOS LOS PICTOGRAMAS
UPDATE stu_picto
SET
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_x'),
`attributes` = JSON_REMOVE(`attributes`, '$.free_category_coord_y'),
`attributes` = JSON_REMOVE(`attributes`, '$.id_cat');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment