Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c78e2d50
authored
Nov 08, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
grid adapt step by step
parent
aa100083
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
54 deletions
sails/roles/database/files/new-grid-system-adapt2.sql
sails/roles/database/files/new-grid-system-adapt2.sql
View file @
c78e2d50
...
@@ -15,58 +15,32 @@ ALTER TABLE `grid` ADD `color` varchar(7) NULL;
...
@@ -15,58 +15,32 @@ ALTER TABLE `grid` ADD `color` varchar(7) NULL;
-- Foreign key stu_picto(id_child_grid) <- grid(id)
-- 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
;
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
$$
-- ESCENAS SIN CATEGORIAS
CREATE
PROCEDURE
new_grid_system
()
-- Pasa los pictos de escenas sin categorias al nuevo sistema
BEGIN
UPDATE
stu_picto
SET
-- Cursor para recorrer los pictos de escenas sin categorias
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
attributes
->
'$.free_category_coord_x'
),
DECLARE
cursor_stu_picto_free_category
CURSOR
FOR
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_y'
,
attributes
->
'$.free_category_coord_y'
)
SELECT
id
,
id_stu
,
attributes
FROM
pictodb
.
stu_picto
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'
;
-- Cursor para recorrer los pictos de escenas con categorias y que se encuentran en la escena principal
-- ESCENAS CON CATEGORIAS
DECLARE
cursor_stu_picto_categories_parent
CURSOR
FOR
-- Pictos principales de las escenas, sólo limpia su JSON
SELECT
id
,
id_stu
,
attributes
FROM
pictodb
.
stu_picto
UPDATE
stu_picto
WHERE
attributes
->>
"$.coord_x"
!=
'null'
AND
attributes
->>
"$.coord_y"
!=
'null'
AND
attributes
->>
"$.id_cat"
=
'null'
;
SET
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_x'
),
-- Cursor para recorrer los pictos de escenas con categorias y que son hijos de alguna categoria
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_y'
),
DECLARE
cursor_stu_picto_categories_child
CURSOR
FOR
SELECT
id
,
id_stu
,
attributes
FROM
pictodb
.
stu_picto
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.id_cat'
)
SELECT
id
,
id_stu
,
attributes
FROM
pictodb
.
stu_picto
WHERE
attributes
->>
"$.coord_x"
!=
'null'
AND
attributes
->>
"$.coord_y"
!=
'null'
AND
attributes
->>
"$.id_cat"
=
'null'
;
WHERE
attributes
->>
"$.coord_x"
!=
'null'
AND
attributes
->>
"$.coord_y"
!=
'null'
AND
attributes
->>
"$.id_cat"
!=
'null'
;
-- Pictos hijos de las escenas
DECLARE
done
INT
DEFAULT
FALSE
;
DELETE
FROM
stu_picto
WHERE
attributes
->>
"$.id_cat"
!=
'null'
;
DECLARE
CONTINUE
HANDLER
FOR
NOT
FOUND
SET
done
=
TRUE
;
OPEN
cursor_stu_picto_free_category
;
-- LIMPIA EL JSON DE TODOS LOS PICTOGRAMAS
read_loop
:
LOOP
UPDATE
stu_picto
SET
FETCH
cursor_stu_picto_free_category
INTO
_id_stu_picto
,
_id_stu
,
_attributes
;
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_x'
),
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_y'
),
-- Control para la finalizacion del bucle
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.id_cat'
);
IF
done
THEN
LEAVE
read_loop
;
END
IF
;
-- Pasa las coordenadas libres a coord_x y coord_y
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
;
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
;
END
LOOP
;
CLOSE
cursor_stu_picto_free_category
;
SET
done
=
FALSE
;
END
$$
DELIMITER
;
CALL
new_grid_system
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment