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
7beaabea
authored
Nov 08, 2017
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
new-grid adapt2 revision
parent
bad6281f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
40 deletions
sails/roles/database/files/new-grid-system-adapt2.sql
sails/roles/database/files/new-grid-system-adapt2.sql
View file @
7beaabea
...
@@ -2,58 +2,65 @@
...
@@ -2,58 +2,65 @@
SET
FOREIGN_KEY_CHECKS
=
0
;
SET
FOREIGN_KEY_CHECKS
=
0
;
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`
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
;
-- ----------------------------------------------------------------------------
-- CAMBIOS EN EL SCHEMA DE pictodb
-- CAMBIOS EN EL SCHEMA DE pictodb
-- Renombrado de tabla y columnas
-- ----------------------------------------------------------------------------
RENAME
TABLE
`scene`
TO
`grid`
;
ALTER
TABLE
`student`
CHANGE
`id_active_scene`
`id_active_grid`
int
(
11
)
NULL
;
ALTER
TABLE
`stu_picto`
ADD
`id_grid`
int
(
11
)
NOT
NULL
;
RENAME
TABLE
`scene`
TO
`grid`
;
ALTER
TABLE
`stu_picto`
ADD
`id_child_grid`
int
(
11
)
NULL
;
ALTER
TABLE
`student`
CHANGE
`id_active_scene`
`id_active_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
`grid`
DROP
COLUMN
`categories`
;
ALTER
TABLE
`stu_picto`
ADD
`id_grid`
int
(
11
)
NOT
NULL
;
ALTER
TABLE
`grid`
ADD
`color`
varchar
(
7
)
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
;
-- ESCENAS CON CATEGORIAS
ALTER
TABLE
`grid`
DROP
COLUMN
`categories`
;
-- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
ALTER
TABLE
`grid`
ADD
`color`
varchar
(
7
)
NULL
;
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
picto_exp
.
text
,
stu_picto
.
id_child_grid
,
stu_picto
.
id_stu
-- ESCENAS CON CATEGORIAS
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
-- Pictos principales: creamos escenas para cada uno de ellos, evitando los de la primera columna
JOIN
stu_picto
AS
B
on
UPDATE
stu_picto
A
.
id_scene
=
B
.
id_scene
AND
SET
id_child_grid
=
id
A
.
id_stu
=
B
.
id_stu
AND
WHERE
attributes
->>
"$.id_cat"
=
'null'
AND
attributes
->>
"$.coord_y"
>
0
;
A
.
attributes
->>
"$.id_cat"
=
B
.
id_pic
SET
A
.
id_grid
=
B
.
id_child_grid
;
-- Pictos hijos: los asociamos a su escena correspondiente
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'
;
-- Pictos hijos: los asociamos a su escena correspondiente
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
SET
A
.
id_grid
=
B
.
id_child_grid
;
-- ----------------------------------------------------------------------------
-- ESCENAS SIN CATEGORIAS
-- ESCENAS SIN CATEGORIAS
-- Pasa los pictos de escenas sin categorias al nuevo sistema
-- ----------------------------------------------------------------------------
UPDATE
stu_picto
SET
-- Pasa los pictos de escenas sin categorias al nuevo sistema
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_x'
,
attributes
->
'$.free_category_coord_x'
),
UPDATE
stu_picto
`attributes`
=
JSON_REPLACE
(
`attributes`
,
'$.coord_y'
,
attributes
->
'$.free_category_coord_y'
)
SET
WHERE
attributes
->>
"$.free_category_coord_x"
!=
'null'
AND
attributes
->>
"$.free_category_coord_y"
!=
'null'
;
`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'
;
-- LIMPIA EL JSON DE TODOS LOS PICTOGRAMAS
-- 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
;
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