blob: 9a9ec8c133f05690b1a59ed8ff04b835bfab19d0 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001-- Copyright 2016 The Chromium Authors
2-- Use of this source code is governed by a BSD-style license that can be
3-- found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5
6DROP PROCEDURE IF EXISTS AttachDanglingRelations;
7
8delimiter //
9
10CREATE PROCEDURE AttachDanglingRelations()
11BEGIN
12 DROP TEMPORARY TABLE IF EXISTS temp_relations;
13
14 CREATE TEMPORARY TABLE temp_relations (
15 old_issue_id INT,
16 old_dst_issue_project VARCHAR(80) COLLATE utf8_unicode_ci,
17 old_dst_issue_local_id INT,
18 old_kind enum('blockedon','blocking','mergedinto') COLLATE utf8_unicode_ci,
19 new_issue_id INT,
20 new_dst_issue_id INT,
21 new_kind enum('blockedon','blocking','mergedinto') COLLATE utf8_unicode_ci
22 );
23
24 INSERT INTO temp_relations
25 SELECT
26 dir.issue_id AS old_issue_id,
27 dir.dst_issue_project AS old_dst_issue_project,
28 dir.dst_issue_local_id AS old_dst_issue_local_id,
29 dir.kind AS old_kind,
30 dir.issue_id AS new_issue_id,
31 i.id AS new_dst_issue_id,
32 dir.kind AS new_kind
33 FROM Issue i
34 JOIN Project p
35 ON i.project_id=p.project_id
36 JOIN DanglingIssueRelation dir
37 ON dir.dst_issue_local_id=i.local_id
38 AND dir.dst_issue_project=p.project_name
39 WHERE dir.kind='blockedon';
40
41 INSERT INTO temp_relations
42 SELECT
43 dir.issue_id AS old_issue_id,
44 dir.dst_issue_project AS old_dst_issue_project,
45 dir.dst_issue_local_id AS old_dst_issue_local_id,
46 dir.kind AS old_kind,
47 dir.issue_id AS new_issue_id,
48 i.id AS new_dst_issue_id,
49 dir.kind AS new_kind
50 FROM Issue i
51 JOIN Project p
52 ON i.project_id=p.project_id
53 JOIN DanglingIssueRelation dir
54 ON dir.dst_issue_local_id=i.local_id
55 AND dir.dst_issue_project=p.project_name
56 WHERE dir.kind='mergedinto';
57
58 INSERT INTO temp_relations
59 SELECT
60 dir.issue_id AS old_issue_id,
61 dir.dst_issue_project AS old_dst_issue_project,
62 dir.dst_issue_local_id AS old_dst_issue_local_id,
63 dir.kind AS old_kind,
64 i.id AS new_issue_id,
65 dir.issue_id AS new_dst_issue_id,
66 'blockedon' AS new_kind
67 FROM Issue i
68 JOIN Project p
69 ON i.project_id=p.project_id
70 JOIN DanglingIssueRelation dir
71 ON dir.dst_issue_local_id=i.local_id
72 AND dir.dst_issue_project=p.project_name
73 WHERE dir.kind='blocking';
74
75 INSERT IGNORE INTO IssueRelation
76 SELECT new_issue_id, new_dst_issue_id, new_kind
77 FROM temp_relations;
78
79 DELETE from DanglingIssueRelation
80 WHERE EXISTS (
81 SELECT NULL FROM temp_relations
82 WHERE issue_id=old_issue_id
83 AND dst_issue_project=old_dst_issue_project
84 AND dst_issue_local_id=old_dst_issue_local_id
85 AND kind=old_kind
86 );
87
88END;
89//
90
91delimiter ;