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