Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | -- Copyright 2019 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | -- There have been cases of imported data that used the wrong email |
| 6 | -- address for a user. This script can change all the user_ids in our |
| 7 | -- database from the ID for old_email to the ID for new_email. |
| 8 | |
| 9 | DROP PROCEDURE IF EXISTS RewriteUserID; |
| 10 | |
| 11 | delimiter // |
| 12 | |
| 13 | CREATE PROCEDURE RewriteUserID( |
| 14 | IN in_old_email VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci, |
| 15 | IN in_new_email VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci) |
| 16 | proc_label:BEGIN |
| 17 | DECLARE old_id INT UNSIGNED; |
| 18 | DECLARE new_id INT UNSIGNED; |
| 19 | |
| 20 | IF in_old_email is NULL OR in_old_email = '' THEN |
| 21 | SELECT CONCAT('in_old_email cannot be null or empty') as ErrorMsg; |
| 22 | LEAVE proc_label; |
| 23 | END IF; |
| 24 | |
| 25 | IF in_new_email is NULL OR in_new_email = '' THEN |
| 26 | SELECT CONCAT('in_new_email cannot be null or empty') as ErrorMsg; |
| 27 | LEAVE proc_label; |
| 28 | END IF; |
| 29 | |
| 30 | SET old_id = (SELECT user_id FROM User WHERE email = in_old_email); |
| 31 | SET new_id = (SELECT user_id FROM User WHERE email = in_new_email); |
| 32 | |
| 33 | IF old_id is NULL THEN |
| 34 | SELECT CONCAT('User ', in_old_email, ' not found') as ErrorMsg; |
| 35 | LEAVE proc_label; |
| 36 | END IF; |
| 37 | |
| 38 | IF new_id is NULL THEN |
| 39 | SELECT CONCAT('User ', in_new_email, ' not found') as ErrorMsg; |
| 40 | LEAVE proc_label; |
| 41 | END IF; |
| 42 | |
| 43 | SELECT CONCAT('Rewriting ', old_id, ' to ', new_id) AS Progress; |
| 44 | |
| 45 | UPDATE Component2Admin SET admin_id = new_id |
| 46 | WHERE admin_id = old_id LIMIT 1000; |
| 47 | |
| 48 | UPDATE Component2Cc SET cc_id = new_id |
| 49 | WHERE cc_id = old_id LIMIT 1000; |
| 50 | |
| 51 | UPDATE FieldDef2Admin SET admin_id = new_id |
| 52 | WHERE admin_id = old_id LIMIT 1000; |
| 53 | |
| 54 | UPDATE Issue SET reporter_id = new_id |
| 55 | WHERE reporter_id = old_id LIMIT 1000; |
| 56 | |
| 57 | UPDATE Issue SET owner_id = new_id |
| 58 | WHERE owner_id = old_id LIMIT 1000; |
| 59 | |
| 60 | UPDATE IGNORE Issue2FieldValue SET user_id = new_id |
| 61 | WHERE user_id = old_id LIMIT 1000; |
| 62 | |
| 63 | UPDATE IGNORE Issue2Cc SET cc_id = new_id |
| 64 | WHERE cc_id = old_id LIMIT 1000; |
| 65 | |
| 66 | UPDATE IGNORE IssueStar SET user_id = new_id |
| 67 | WHERE user_id = old_id LIMIT 1000; |
| 68 | |
| 69 | UPDATE Comment SET commenter_id = new_id |
| 70 | WHERE commenter_id = old_id LIMIT 10000; |
| 71 | |
| 72 | UPDATE IssueUpdate SET added_user_id = new_id |
| 73 | WHERE added_user_id = old_id LIMIT 10000; |
| 74 | |
| 75 | UPDATE IssueUpdate SET removed_user_id = new_id |
| 76 | WHERE removed_user_id = old_id LIMIT 10000; |
| 77 | |
| 78 | UPDATE Template SET owner_id = new_id |
| 79 | WHERE owner_id = old_id LIMIT 1000; |
| 80 | |
| 81 | UPDATE Template2Admin SET admin_id = new_id |
| 82 | WHERE admin_id = old_id LIMIT 1000; |
| 83 | |
| 84 | -- Ignore filter rules, saved queries, hotlists, deleted_by, approvers. |
| 85 | |
| 86 | UPDATE IssueSnapshot SET reporter_id = new_id |
| 87 | WHERE reporter_id = old_id LIMIT 10000; |
| 88 | |
| 89 | UPDATE IssueSnapshot SET owner_id = new_id |
| 90 | WHERE owner_id = old_id LIMIT 10000; |
| 91 | |
| 92 | UPDATE IGNORE IssueSnapshot2Cc SET cc_id = new_id |
| 93 | WHERE cc_id = old_id LIMIT 10000; |
| 94 | |
| 95 | END; |
| 96 | |
| 97 | // |
| 98 | |
| 99 | delimiter ; |