working on adapt

parent 3f943cae
...@@ -4,22 +4,37 @@ DELETE FROM stu_picto WHERE id_scene NOT IN (SELECT s.id FROM scene s); ...@@ -4,22 +4,37 @@ DELETE FROM stu_picto WHERE id_scene NOT IN (SELECT s.id FROM scene s);
ALTER TABLE `stu_picto` ADD CONSTRAINT `stu_picto_scene_fk` FOREIGN KEY (`id_scene`) REFERENCES `scene` (`id`) ON DELETE CASCADE; ALTER TABLE `stu_picto` ADD CONSTRAINT `stu_picto_scene_fk` FOREIGN KEY (`id_scene`) REFERENCES `scene` (`id`) ON DELETE CASCADE;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
-- Rename columns -- CAMBIOS EN EL SCHEMA DE pictodb
RENAME TABLE `scene` TO `grid`; -- Renombrado de tabla y columnas
ALTER TABLE `stu_picto` CHANGE `id_scene` `id_grid` int(11) NOT NULL; RENAME TABLE `scene` TO `grid`;
ALTER TABLE `student` CHANGE `id_active_scene` `id_active_grid` int(11) NULL; ALTER TABLE `stu_picto` CHANGE `id_scene` `id_grid` int(11) NOT NULL;
ALTER TABLE `student` CHANGE `id_active_scene` `id_active_grid` int(11) NULL;
-- Nueva columna 'id_child_grid'
ALTER TABLE `stu_picto` ADD `id_child_grid` int(11) NULL;
-- Elimina columna categorias 'categories'
ALTER TABLE `grid` DROP COLUMN `categories`;
-- Color del grid pasa a ser una columna
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;
-- Add new column 'id_child_grid' -- ESCENAS CON CATEGORIAS
ALTER TABLE `stu_picto` ADD `id_child_grid` int(11) NULL; -- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
UPDATE stu_picto
SET id_child_grid = id
WHERE attributes->>"$.id_cat" = 'null' AND attributes->>"$.coord_x" > 0;
INSERT INTO grid(SELECT ¿NAME?, id_child_grid FROM stu_picto WHERE id_child_grid IS NOT NULL);
-- Drop column 'categories' UPDATE stu_picto AS A
ALTER TABLE `grid` DROP COLUMN `categories`; JOIN stu_picto AS B on
A.id_scene = B.id_scene AND
A.id_stu = B.id_stu AND
A.id_cat = B.id_pic
SET A.id_grid = B.id_child_grid;
-- Add color to grid column -- Pictos hijos: los asociamos a su escena correspondiente
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;
-- ESCENAS SIN CATEGORIAS -- ESCENAS SIN CATEGORIAS
...@@ -31,19 +46,6 @@ ALTER TABLE stu_picto ADD FOREIGN KEY(id_child_grid) REFERENCES grid(id) ON DELE ...@@ -31,19 +46,6 @@ ALTER TABLE stu_picto ADD FOREIGN KEY(id_child_grid) REFERENCES grid(id) ON DELE
WHERE attributes->>"$.free_category_coord_x" != 'null' AND attributes->>"$.free_category_coord_y" != 'null'; WHERE attributes->>"$.free_category_coord_x" != 'null' AND attributes->>"$.free_category_coord_y" != 'null';
-- ESCENAS CON CATEGORIAS
-- Pictos principales de las escenas con categorias, 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 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';
-- LIMPIA EL JSON DE TODOS LOS PICTOGRAMAS -- LIMPIA EL JSON DE TODOS LOS PICTOGRAMAS
UPDATE stu_picto UPDATE stu_picto
SET SET
......
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