This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate-to-prox-backend.sql
124 lines (103 loc) · 3.96 KB
/
migrate-to-prox-backend.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
This files contains scripts used to migrate data from the services database to prox-backend database.
*/
/* discipline */
SELECT
d.key,
d.name,
current_timestamp as created_at,
current_timestamp as modified_at
FROM specializations d
/* module_type */
SELECT
m.key,
m.name,
true as active,
current_timestamp as created_at,
current_timestamp as modified_at
FROM module_type m
/* module_type_disciplines */
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('BA', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('BA', 'ING');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('PP', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('IP', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('WIP', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('ITMP', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('MA', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('MA', 'ING');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('TP', 'ING');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('PA', 'ING');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('QQ1', 'INF');
INSERT INTO module_type_disciplines(module_type_key, disciplines_key) VALUES ('QQ2', 'INF');
/* curriculum_context */
create temporary table temp_project_curriculum as (
SELECT
gen_random_uuid() as id,
project.id as project_id
FROM project
);
SELECT tpc.id FROM temp_project_curriculum tpc;
/* curriculum_context_module_types */
SELECT
tpc.id as curriculum_context_id,
m.key as module_types_key
FROM project p
JOIN project_modules pm on p.id = pm.project_id
JOIN module_type m on pm.modules_id = m.id
JOIN temp_project_curriculum tpc on p.id = tpc.project_id;
/* curriculum_context_disciplines */
SELECT
tpc.id as curriculum_context_id,
s.key as disciplines_key
FROM project p
JOIN project_specializations pm on p.id = pm.project_id
JOIN specializations s on s.id = pm.specializations_id
JOIN temp_project_curriculum tpc on p.id = tpc.project_id;
/* project */
create temporary table temp_state_translation as (
VALUES
(0, 'OFFERED'),
(1, 'RUNNING'),
(2, 'COMPLETED')
);
SELECT
p.id as id,
p.description as description,
p.requirement as requirement,
p.short_description as summary,
p.name as title,
tpc.id as curriculum_context_id,
s.column2 as state,
org.id as organization_id,
current_timestamp as created_at,
current_timestamp as modified_at,
current_timestamp as updated_at
FROM project p
JOIN temp_state_translation s ON s.column1 = p.status
LEFT JOIN (SELECT * FROM abstract_owner o WHERE o.owner_type = 'organization') org ON org.id = p.owner_id
LEFT JOIN temp_project_curriculum tpc on p.id = tpc.project_id;
SELECT * FROM proposal WHERE committed_supervisor is null;
create temporary table temp_state_translation_proposal as (
VALUES
(0, 'PROPOSED'),
(1, 'ARCHIVED'),
(2, 'STALE')
);
SELECT
p.id as id,
p.description as description,
p.requirement as requirement,
p.name as title,
tpc.id as curriculum_context_id,
s.column2 as state,
org.id as organization_id,
current_timestamp as created_at,
current_timestamp as modified_at,
current_timestamp as updated_at
FROM proposal p
JOIN temp_state_translation_proposal s ON s.column1 = p.status
LEFT JOIN (SELECT * FROM abstract_owner o WHERE o.owner_type = 'organization') org ON org.id = p.owner_id
LEFT JOIN temp_project_curriculum tpc on p.id = tpc.project_id;
SELECT * FROM project;
/* project_supervisors */
SELECT project_id, id as lecturer_id FROM project_supervisors;