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