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
d7a4cfd1
authored
Nov 08, 2017
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
new-grid adapt2 revision
parent
05a863aa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
sails/roles/database/files/new-grid-system-adapt2.sql
sails/roles/database/files/new-grid-system-adapt2.sql
View file @
d7a4cfd1
...
@@ -2,16 +2,17 @@ SET FOREIGN_KEY_CHECKS = 0;
...
@@ -2,16 +2,17 @@ SET FOREIGN_KEY_CHECKS = 0;
-- Purgamos base de datos antes
-- Purgamos base de datos antes
DELETE
FROM
stu_picto
WHERE
id_scene
NOT
IN
(
SELECT
s
.
id
FROM
scene
s
);
DELETE
FROM
stu_picto
WHERE
id_scene
NOT
IN
(
SELECT
s
.
id
FROM
scene
s
);
ALTER
TABLE
`stu_picto`
DROP
FOREIGN
KEY
`id_scene`
;
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- CAMBIOS EN EL SCHEMA DE pictodb
-- CAMBIOS EN EL SCHEMA DE pictodb
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
SELECT
"Actualizando esquema"
;
RENAME
TABLE
`scene`
TO
`grid`
;
RENAME
TABLE
`scene`
TO
`grid`
;
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
;
ALTER
TABLE
`stu_picto`
ADD
`id_grid`
int
(
11
)
NOT
NULL
;
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
;
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
`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
;
ALTER
TABLE
`stu_picto`
ADD
FOREIGN
KEY
(
`id_grid`
)
REFERENCES
`grid`
(
`id`
)
ON
DELETE
CASCADE
;
...
@@ -22,10 +23,15 @@ ALTER TABLE `grid` ADD `color` varchar(7) NULL;
...
@@ -22,10 +23,15 @@ ALTER TABLE `grid` ADD `color` varchar(7) NULL;
-- ESCENAS CON CATEGORIAS
-- 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
-- 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_y"
>
0
;
WHERE
attributes
->>
"$.id_cat"
=
'null'
AND
attributes
->>
"$.coord_y"
>
0
AND
attributes
->
'$.free_category_coord_x'
=
'null'
;
INSERT
INTO
grid
(
name
,
id
,
id_stu
)
INSERT
INTO
grid
(
name
,
id
,
id_stu
)
SELECT
picto_exp
.
text
,
stu_picto
.
id_child_grid
,
stu_picto
.
id_stu
SELECT
picto_exp
.
text
,
stu_picto
.
id_child_grid
,
stu_picto
.
id_stu
...
@@ -37,6 +43,8 @@ WHERE
...
@@ -37,6 +43,8 @@ WHERE
-- Pictos hijos: los asociamos a su escena correspondiente
-- Pictos hijos: los asociamos a su escena correspondiente
SELECT
"Asociando pictos a tableros..."
;
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
...
@@ -48,19 +56,31 @@ SET A.id_grid = B.id_child_grid;
...
@@ -48,19 +56,31 @@ SET A.id_grid = B.id_child_grid;
-- ESCENAS SIN CATEGORIAS
-- ESCENAS SIN CATEGORIAS
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Pasa los pictos de escenas sin categorias al nuevo sistema
SELECT
"Transformando escenas sin categorías en tableros..."
;
UPDATE
stu_picto
SET
id_grid
=
id_scene
WHERE
id_grid
IS
NULL
;
-- Adaptamos JSON
UPDATE
stu_picto
UPDATE
stu_picto
SET
SET
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
attributes
->
'$.free_category_coord_x'
),
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
attributes
->
'$.free_category_coord_x'
),
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_y'
,
attributes
->
'$.free_category_coord_y'
)
`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'
;
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`
;
-- LIMPIA EL JSON DE TODOS LOS PICTOGRAMAS
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'
);
`attributes`
=
JSON_REMOVE
(
`attributes`
,
'$.id_cat'
);
SET
FOREIGN_KEY_CHECKS
=
1
;
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