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
bad6281f
authored
Nov 08, 2017
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
new-grid adapt2 revision
parent
ade32dfd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
12 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 @
bad6281f
--- ---------------------------------------------------------------------------
---
--- Adaptación de la base de datos al nuevo esquema
---
--- ---------------------------------------------------------------------------
-- Rename columns
-- Rename columns
RENAME
TABLE
`scene`
TO
`grid`
;
RENAME
TABLE
`scene`
TO
`grid`
;
ALTER
TABLE
`stu_picto`
CHANGE
`id_scene`
`id_grid`
int
(
11
)
NOT
NULL
;
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;
...
@@ -15,6 +21,12 @@ 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
;
--- ---------------------------------------------------------------------------
---
--- Migración de los datos al nuevo esquema
---
--- ---------------------------------------------------------------------------
DELIMITER
$$
DELIMITER
$$
DROP
PROCEDURE
IF
EXISTS
new_grid_system
$$
DROP
PROCEDURE
IF
EXISTS
new_grid_system
$$
...
@@ -64,7 +76,6 @@ BEGIN
...
@@ -64,7 +76,6 @@ BEGIN
SELECT
_attributes
->>
"$.free_category_coord_y"
INTO
_free_category_coord_y
;
SELECT
_attributes
->>
"$.free_category_coord_y"
INTO
_free_category_coord_y
;
END
IF
;
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
IF
_attributes
->>
"$.id_cat"
=
'null'
THEN
SET
_id_cat
=
NULL
;
SET
_id_cat
=
NULL
;
ELSE
ELSE
...
@@ -75,7 +86,8 @@ BEGIN
...
@@ -75,7 +86,8 @@ BEGIN
UPDATE
stu_picto
UPDATE
stu_picto
SET
SET
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.free_category_coord_x'
),
`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
;
WHERE
id
=
_id_stu_picto
;
-- Pictogramas que estan en escenas sin categorias
-- Pictogramas que estan en escenas sin categorias
...
@@ -86,7 +98,7 @@ BEGIN
...
@@ -86,7 +98,7 @@ BEGIN
SET
SET
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
_free_category_coord_x
),
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
_free_category_coord_x
),
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_y'
,
_free_category_coord_y
),
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_y'
,
_free_category_coord_y
),
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.id_cat'
)
WHERE
id
=
_id_stu_picto
;
WHERE
id
=
_id_stu_picto
;
-- Pictogramas que estan en escenas con categorias
-- Pictogramas que estan en escenas con categorias
...
...
sails/roles/database/files/new-grid-system-adapt2.sql
View file @
bad6281f
...
@@ -7,30 +7,35 @@ SET FOREIGN_KEY_CHECKS = 1;
...
@@ -7,30 +7,35 @@ SET FOREIGN_KEY_CHECKS = 1;
-- CAMBIOS EN EL SCHEMA DE pictodb
-- CAMBIOS EN EL SCHEMA DE pictodb
-- Renombrado de tabla y columnas
-- Renombrado de tabla y columnas
RENAME
TABLE
`scene`
TO
`grid`
;
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
;
ALTER
TABLE
`student`
CHANGE
`id_active_scene`
`id_active_grid`
int
(
11
)
NULL
;
-- Nueva columna 'id_child_grid'
ALTER
TABLE
`stu_picto`
ADD
`id_grid`
int
(
11
)
NOT
NULL
;
ALTER
TABLE
`stu_picto`
ADD
`id_child_grid`
int
(
11
)
NULL
;
ALTER
TABLE
`stu_picto`
ADD
`id_child_grid`
int
(
11
)
NULL
;
-- Elimina columna categorias 'categories'
ALTER
TABLE
`stu_picto`
DROP
COLUMN
`id_scene`
;
ALTER
TABLE
`stu_picto`
ADD
FOREIGN
KEY
(
id_child_grid
)
REFERENCES
grid
(
id
)
ON
DELETE
SET
NULL
;
ALTER
TABLE
`grid`
DROP
COLUMN
`categories`
;
ALTER
TABLE
`grid`
DROP
COLUMN
`categories`
;
-- Color del grid pasa a ser una columna
ALTER
TABLE
`grid`
ADD
`color`
varchar
(
7
)
NULL
;
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
-- ESCENAS CON CATEGORIAS
-- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
-- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
UPDATE
stu_picto
UPDATE
stu_picto
SET
id_child_grid
=
id
SET
id_child_grid
=
id
WHERE
attributes
->>
"$.id_cat"
=
'null'
AND
attributes
->>
"$.coord_
x
"
>
0
;
WHERE
attributes
->>
"$.id_cat"
=
'null'
AND
attributes
->>
"$.coord_
y
"
>
0
;
INSERT
INTO
grid
(
SELECT
¿
NAME
?
,
id_child_grid
FROM
stu_picto
WHERE
id_child_grid
IS
NOT
NULL
);
INSERT
INTO
grid
(
name
,
id
,
id_stu
)
SELECT
picto_exp
.
text
,
stu_picto
.
id_child_grid
,
stu_picto
.
id_stu
FROM
stu_picto
,
picto_exp
WHERE
stu_picto
.
id_child_grid
IS
NOT
NULL
AND
stu_picto
.
id_pic
=
picto_exp
.
id_pic
AND
picto_exp
.
lang
=
'es-es'
;
UPDATE
stu_picto
AS
A
UPDATE
stu_picto
AS
A
JOIN
stu_picto
AS
B
on
JOIN
stu_picto
AS
B
on
A
.
id_scene
=
B
.
id_scene
AND
A
.
id_scene
=
B
.
id_scene
AND
A
.
id_stu
=
B
.
id_stu
AND
A
.
id_stu
=
B
.
id_stu
AND
A
.
id_cat
=
B
.
id_pic
A
.
attributes
->>
"$.id_cat"
=
B
.
id_pic
SET
A
.
id_grid
=
B
.
id_child_grid
;
SET
A
.
id_grid
=
B
.
id_child_grid
;
-- Pictos hijos: los asociamos a su escena correspondiente
-- Pictos hijos: los asociamos a su escena correspondiente
...
...
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