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
9f15998d
authored
Nov 09, 2017
by
german callejas
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
parents
8d0e0809
d17abfc6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
40 deletions
sails/roles/database/files/new-grid-system-adapt.sql
sails/roles/database/files/new-grid-system-adapt2.sql
sails/roles/database/files/new-grid-system-adapt.sql
View file @
9f15998d
--- ---------------------------------------------------------------------------
---
--- Adaptación de la base de datos al nuevo esquema
---
--- ---------------------------------------------------------------------------
-- Rename columns
RENAME
TABLE
`scene`
TO
`grid`
;
ALTER
TABLE
`stu_picto`
CHANGE
`id_scene`
`id_grid`
int
(
11
)
NOT
NULL
;
...
...
@@ -15,6 +21,12 @@ 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
;
--- ---------------------------------------------------------------------------
---
--- Migración de los datos al nuevo esquema
---
--- ---------------------------------------------------------------------------
DELIMITER
$$
DROP
PROCEDURE
IF
EXISTS
new_grid_system
$$
...
...
@@ -64,7 +76,6 @@ BEGIN
SELECT
_attributes
->>
"$.free_category_coord_y"
INTO
_free_category_coord_y
;
END
IF
;
-- Esto hay que hacerlo porque el null procediente del JSON para id_cat lo reconoce como un literal
IF
_attributes
->>
"$.id_cat"
=
'null'
THEN
SET
_id_cat
=
NULL
;
ELSE
...
...
@@ -75,7 +86,8 @@ BEGIN
UPDATE
stu_picto
SET
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_x'
),
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_y'
)
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_y'
),
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.id_cat'
)
WHERE
id
=
_id_stu_picto
;
-- Pictogramas que estan en escenas sin categorias
...
...
@@ -86,7 +98,7 @@ BEGIN
SET
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
_free_category_coord_x
),
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_y'
,
_free_category_coord_y
),
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.id_cat'
)
WHERE
id
=
_id_stu_picto
;
-- Pictogramas que estan en escenas con categorias
...
...
sails/roles/database/files/new-grid-system-adapt2.sql
View file @
9f15998d
-- Correccion de integridad por error en DEV, antes de cambiar los nombres
SET
FOREIGN_KEY_CHECKS
=
0
;
-- Purgamos base de datos antes
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
;
SET
FOREIGN_KEY_CHECKS
=
1
;
ALTER
TABLE
`stu_picto`
DROP
FOREIGN
KEY
`stu_picto_scene_fk`
;
ALTER
TABLE
`stu_picto`
DROP
INDEX
`stu_picto_scene_fk`
;
-- ----------------------------------------------------------------------------
-- CAMBIOS EN EL SCHEMA DE pictodb
-- ----------------------------------------------------------------------------
SELECT
"Actualizando esquema"
;
-- Rename columns
RENAME
TABLE
`scene`
TO
`grid`
;
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
;
-- Add new column 'id_child_grid'
ALTER
TABLE
`stu_picto`
ADD
`id_grid`
int
(
11
)
NULL
;
ALTER
TABLE
`stu_picto`
ADD
`id_child_grid`
int
(
11
)
NULL
;
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_grid`
)
REFERENCES
`grid`
(
`id`
)
ON
DELETE
CASCADE
;
-- Drop column 'categories'
ALTER
TABLE
`grid`
DROP
COLUMN
`categories`
;
-- Add color to grid column
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 CON CATEGORIAS
-- ----------------------------------------------------------------------------
SELECT
"Creando tableros para los pictos con categorías..."
;
-- 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_y"
>
0
;
INSERT
INTO
grid
(
name
,
id
,
id_stu
)
SELECT
pe
.
text
,
sp
.
id_child_grid
,
sp
.
id_stu
FROM
stu_picto
sp
JOIN
picto_exp
pe
ON
sp
.
id_child_grid
IS
NOT
NULL
AND
pe
.
id
=
(
SELECT
pe2
.
id
FROM
picto_exp
pe2
WHERE
pe2
.
id_pic
=
sp
.
id_pic
AND
pe2
.
lang
=
"es-es"
LIMIT
1
);
-- Pictos hijos: los asociamos a su escena correspondiente
SELECT
"Asociando pictos bajo categorías a tableros..."
;
UPDATE
stu_picto
AS
A
JOIN
stu_picto
AS
B
on
A
.
id_scene
=
B
.
id_scene
AND
A
.
id_stu
=
B
.
id_stu
AND
A
.
attributes
->>
"$.id_cat"
=
B
.
id_pic
AND
B
.
attributes
->>
"$.id_cat"
=
'null'
AND
B
.
attributes
->>
"$.coord_y"
>
0
SET
A
.
id_grid
=
B
.
id_child_grid
;
-- ----------------------------------------------------------------------------
-- ESCENAS SIN CATEGORIAS
-- Pasa los pictos de escenas sin categorias al nuevo sistema
UPDATE
stu_picto
SET
`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'
;
-- ----------------------------------------------------------------------------
SELECT
"Asociamos pictos que no están bajo categorías (los de primer nivel o libres) a tableros"
;
-- 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
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'
);
UPDATE
stu_picto
SET
id_grid
=
id_scene
WHERE
id_grid
IS
NULL
;
-- Adaptamos JSON
UPDATE
stu_picto
SET
`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'
;
-- ----------------------------------------------------------------------------
-- Cambios finales de esquema
-- ----------------------------------------------------------------------------
SELECT
"Cambios finales en el esquema y purga del JSON de stu_picto"
;
ALTER
TABLE
`stu_picto`
DROP
COLUMN
`id_scene`
;
ALTER
TABLE
`stu_picto`
CHANGE
`id_grid`
`id_grid`
int
(
11
)
NOT
NULL
;
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'
);
SET
FOREIGN_KEY_CHECKS
=
1
;
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