You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since adding the script in 2020 with 7ab4c63, many tables have changed. Hence, we use this opportunity to update the script, allowing it to be used with the current database design. Furthermore, we also keep more data if possible, smoothing a migration.
Unfortunately, migrating exercises got a bit more complicated due to programming groups, community solutions, and tips.
Since we didn't require a migration for these yet, we just added a safeguard for now (acknowledging that some foreign key constraints might still be missing).
Copy file name to clipboardExpand all lines: db/scripts/migrate_exercise.sql
+79-4Lines changed: 79 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,29 @@ BEGIN
10
10
RETURN;
11
11
END IF;
12
12
13
+
IF EXISTS(SELECT1
14
+
FROM exercise_tips
15
+
WHERE exercise_id = duplicated_exercise) THEN
16
+
RAISE NOTICE 'Exercise % has tips. Please migrate tips manually and try again', duplicated_exercise;
17
+
RETURN;
18
+
END IF;
19
+
20
+
IF EXISTS(SELECT1
21
+
FROM community_solutions
22
+
WHERE exercise_id = duplicated_exercise) THEN
23
+
RAISE NOTICE 'Exercise % has a community solution. Please migrate the community solution and their contribution (locks) manually and try again', duplicated_exercise;
24
+
RETURN;
25
+
END IF;
26
+
27
+
IF EXISTS(SELECT1
28
+
FROM programming_groups a, programming_groups b
29
+
WHERE (a.exercise_id= target_exercise ANDb.exercise_id= duplicated_exercise)
30
+
OR (a.exercise_id= duplicated_exercise ANDb.exercise_id= target_exercise)) THEN
31
+
RAISE NOTICE 'Both, exercise % and % have programming groups. Please re-consider the effects (and change the script).', target_exercise, duplicated_exercise;
32
+
RETURN;
33
+
END IF;
34
+
35
+
UPDATE programming_groups SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
13
36
UPDATE submissions SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
14
37
UPDATE request_for_comments SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
15
38
@@ -36,11 +59,63 @@ BEGIN
36
59
UPDATE events SET exercise_id = target_exercise where exercise_id = duplicated_exercise;
37
60
UPDATE searches SET exercise_id = target_exercise where exercise_id = duplicated_exercise;
38
61
UPDATE user_exercise_interventions SET exercise_id = target_exercise where exercise_id = duplicated_exercise;
62
+
63
+
WITH existing_user_proxy_exercise_exercises AS (SELECT CONCAT(user_type, '_', user_id, '_', proxy_exercise_id) as existing
64
+
FROM user_proxy_exercise_exercises
65
+
WHERE exercise_id = target_exercise)
66
+
DELETEFROM user_proxy_exercise_exercises
67
+
WHERE exercise_id = duplicated_exercise
68
+
AND CONCAT(user_type, '_', user_id, '_', proxy_exercise_id) IN (SELECT existing FROM existing_user_proxy_exercise_exercises);
69
+
39
70
UPDATE user_proxy_exercise_exercises SET exercise_id = target_exercise where exercise_id = duplicated_exercise;
40
71
41
-
DELETEFROM anomaly_notifications WHERE exercise_id = duplicated_exercise;
42
-
DELETEFROM exercise_tags WHERE exercise_id = duplicated_exercise;
43
-
DELETEFROM lti_parameters WHERE exercise_id = duplicated_exercise;
72
+
WITH existing_anomaly_notifications AS (SELECT CONCAT(contributor_type, '_', contributor_id, '_', exercise_collection_id) as existing
73
+
FROM anomaly_notifications
74
+
WHERE exercise_id = target_exercise)
75
+
DELETEFROM anomaly_notifications WHERE exercise_id = duplicated_exercise
76
+
AND CONCAT(contributor_type, '_', contributor_id, '_', exercise_collection_id) IN (SELECT existing FROM existing_anomaly_notifications);
77
+
78
+
UPDATE anomaly_notifications SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
79
+
80
+
WITH existing_exercise_tags AS (SELECT tag_id as existing
81
+
FROM exercise_tags
82
+
WHERE exercise_id = tag_id)
83
+
DELETEFROM exercise_tags
84
+
WHERE tag_id = duplicated_exercise
85
+
AND tag_id IN (SELECT existing FROM existing_exercise_tags);
86
+
87
+
UPDATE exercise_tags SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
88
+
89
+
WITH existing_lti_parameters AS (SELECT CONCAT(external_user_id, '_', study_group_id) as existing
90
+
FROM lti_parameters
91
+
WHERE exercise_id = target_exercise)
92
+
DELETEFROM lti_parameters
93
+
WHERE exercise_id = duplicated_exercise
94
+
AND CONCAT(external_user_id, '_', study_group_id) IN (SELECT existing FROM existing_lti_parameters);
95
+
96
+
UPDATE lti_parameters SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
97
+
98
+
WITH existing_pair_programming_exercise_feedbacks
99
+
AS (SELECT CONCAT(user_type, '_', user_id, '_', study_group_id, '_', programming_group_id) as existing
100
+
FROM pair_programming_exercise_feedbacks
101
+
WHERE exercise_id = target_exercise)
102
+
DELETEFROM pair_programming_exercise_feedbacks
103
+
WHERE exercise_id = duplicated_exercise
104
+
AND CONCAT(user_type, '_', user_id, '_', study_group_id, '_', programming_group_id) IN
105
+
(SELECT existing FROM existing_pair_programming_exercise_feedbacks);
106
+
107
+
UPDATE pair_programming_exercise_feedbacks SET exercise_id = target_exercise WHERE user_id = duplicated_exercise;
108
+
109
+
WITH existing_pair_programming_waiting_users AS (SELECT CONCAT(user_type, '_', user_id) as existing
110
+
FROM pair_programming_waiting_users
111
+
WHERE exercise_id = target_exercise)
112
+
DELETEFROM pair_programming_waiting_users
113
+
WHERE exercise_id = duplicated_exercise
114
+
AND CONCAT(user_type, '_', user_id) IN (SELECT existing FROM existing_pair_programming_waiting_users);
115
+
116
+
UPDATE pair_programming_waiting_users SET exercise_id = target_exercise WHERE exercise_id = duplicated_exercise;
117
+
118
+
-- We need to invalidate the remove evaluation mappings for the duplicated exercise, since the local file mapping (within the `.co` file) is broken otherwise.
44
119
DELETEFROM remote_evaluation_mappings WHERE exercise_id = duplicated_exercise;
45
120
46
121
-- Preventing duplicated entries in exercise_collection_items
0 commit comments