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