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 BackfillCommentContentID; |
| 9 | |
| 10 | delimiter // |
| 11 | |
| 12 | CREATE PROCEDURE BackfillCommentContentID( |
| 13 | IN in_start INT, IN in_stop INT, IN in_step INT) |
| 14 | BEGIN |
| 15 | comment_loop: LOOP |
| 16 | IF in_start >= in_stop THEN |
| 17 | LEAVE comment_loop; |
| 18 | END IF; |
| 19 | |
| 20 | SELECT in_start AS StartingAt; |
| 21 | SELECT count(*) |
| 22 | FROM CommentContent |
| 23 | WHERE comment_id >= in_start |
| 24 | AND comment_id < in_start + in_step; |
| 25 | |
| 26 | DROP TEMPORARY TABLE IF EXISTS temp_comment; |
| 27 | CREATE TEMPORARY TABLE temp_comment ( |
| 28 | id INT NOT NULL, |
| 29 | issue_id INT NOT NULL, |
| 30 | created INT NOT NULL, |
| 31 | project_id SMALLINT UNSIGNED NOT NULL, |
| 32 | commenter_id INT UNSIGNED NOT NULL, |
| 33 | commentcontent_id INT UNSIGNED NOT NULL, |
| 34 | deleted_by INT UNSIGNED, |
| 35 | is_spam BOOLEAN DEFAULT FALSE, |
| 36 | is_description BOOLEAN DEFAULT FALSE, |
| 37 | |
| 38 | PRIMARY KEY(id) |
| 39 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
| 40 | |
| 41 | |
| 42 | INSERT INTO temp_comment |
| 43 | SELECT Comment.id, Comment.issue_id, Comment.created, Comment.project_id, |
| 44 | Comment.commenter_id, CommentContent.id, |
| 45 | Comment.deleted_by, Comment.is_spam, Comment.is_description |
| 46 | FROM Comment |
| 47 | LEFT JOIN CommentContent on CommentContent.comment_id = Comment.id |
| 48 | WHERE CommentContent.comment_id >= in_start |
| 49 | AND CommentContent.comment_id < in_start + in_step; |
| 50 | |
| 51 | |
| 52 | REPLACE INTO Comment (id, issue_id, created, project_id, commenter_id, |
| 53 | commentcontent_id, deleted_by, is_spam, is_description) |
| 54 | SELECT id, issue_id, created, project_id, commenter_id, |
| 55 | commentcontent_id, deleted_by, is_spam, is_description |
| 56 | FROM temp_comment; |
| 57 | |
| 58 | SET in_start = in_start + in_step; |
| 59 | |
| 60 | END LOOP; |
| 61 | |
| 62 | END; |
| 63 | |
| 64 | |
| 65 | // |
| 66 | |
| 67 | |
| 68 | delimiter ; |
| 69 | |
| 70 | |
| 71 | -- Temporarily disable these foreign key references so that we can do |
| 72 | -- REPLACE commands. |
| 73 | -- ALTER TABLE SpamReport DROP FOREIGN KEY spamreport_ibfk_2; |
| 74 | -- ALTER TABLE SpamVerdict DROP FOREIGN KEY spamverdict_ibfk_2; |
| 75 | |
| 76 | -- If run locally do all at once: |
| 77 | -- CALL BackfillCommentContentID( 0, 1 * 1000000, 10000); |
| 78 | |
| 79 | -- If run on staging or production, do it in steps and check that |
| 80 | -- users are not hitting errors or timeouts as you go: |
| 81 | -- CALL BackfillCommentContentID( 0, 13 * 1000000, 10000); |
| 82 | -- CALL BackfillCommentContentID(13 * 1000000, 16 * 1000000, 10000); |
| 83 | -- CALL BackfillCommentContentID(16 * 1000000, 17 * 1000000, 10000); |
| 84 | -- CALL BackfillCommentContentID(17 * 1000000, 18 * 1000000, 10000); |
| 85 | -- CALL BackfillCommentContentID(18 * 1000000, 19 * 1000000, 10000); |
| 86 | -- CALL BackfillCommentContentID(19 * 1000000, 20 * 1000000, 10000); |
| 87 | -- CALL BackfillCommentContentID(20 * 1000000, 21 * 1000000, 10000); |
| 88 | -- CALL BackfillCommentContentID(21 * 1000000, 22 * 1000000, 10000); |
| 89 | -- CALL BackfillCommentContentID(22 * 1000000, 23 * 1000000, 10000); |
| 90 | -- CALL BackfillCommentContentID(23 * 1000000, 24 * 1000000, 10000); |
| 91 | -- CALL BackfillCommentContentID(24 * 1000000, 25 * 1000000, 10000); |
| 92 | -- CALL BackfillCommentContentID(25 * 1000000, 26 * 1000000, 10000); |
| 93 | -- CALL BackfillCommentContentID(26 * 1000000, 27 * 1000000, 10000); |
| 94 | -- CALL BackfillCommentContentID(27 * 1000000, 28 * 1000000, 10000); |
| 95 | -- CALL BackfillCommentContentID(28 * 1000000, 29 * 1000000, 10000); |
| 96 | -- CALL BackfillCommentContentID(29 * 1000000, 30 * 1000000, 10000); |
| 97 | -- CALL BackfillCommentContentID(30 * 1000000, 40 * 1000000, 10000); |
| 98 | |
| 99 | -- Add back foreign key constraints. |
| 100 | -- ALTER TABLE SpamReport ADD FOREIGN KEY (comment_id) REFERENCES Comment(id); |
| 101 | -- ALTER TABLE SpamVerdict ADD FOREIGN KEY (comment_id) REFERENCES Comment(id); |