blob: 4eb5f4788602b9e6b2166ce2e821fe99b7739541 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001-- 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
8DROP PROCEDURE IF EXISTS CopyNewCommentContentBackToComment;
9
10delimiter //
11
12CREATE PROCEDURE CopyNewCommentContentBackToComment(
13 IN in_start INT, IN in_stop INT, IN in_step INT)
14BEGIN
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 content MEDIUMTEXT COLLATE utf8mb4_unicode_ci,
34 inbound_message MEDIUMTEXT COLLATE utf8mb4_unicode_ci,
35 deleted_by INT UNSIGNED,
36 is_spam BOOLEAN DEFAULT FALSE,
37 is_description BOOLEAN DEFAULT FALSE,
38
39 PRIMARY KEY(id)
40 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
41
42
43 INSERT INTO temp_comment
44 SELECT Comment.id, Comment.issue_id, Comment.created, Comment.project_id,
45 Comment.commenter_id, CommentContent.content,
46 CommentContent.inbound_message, Comment.deleted_by, Comment.is_spam,
47 Comment.is_description
48 FROM Comment
49 LEFT JOIN CommentContent on CommentContent.comment_id = Comment.id
50 WHERE CommentContent.comment_id >= in_start
51 AND CommentContent.comment_id < in_start + in_step;
52
53
54 REPLACE INTO Comment (id, issue_id, created, project_id, commenter_id,
55 content, inbound_message, deleted_by, is_spam, is_description)
56 SELECT id, issue_id, created, project_id, commenter_id,
57 content, inbound_message, deleted_by, is_spam, is_description
58 FROM temp_comment;
59
60 SET in_start = in_start + in_step;
61
62 END LOOP;
63
64END;
65
66
67//
68
69
70delimiter ;
71
72
73-- Temporarily disable these foreign key references so that we can do
74-- REPLACE commands.
75-- ALTER TABLE SpamReport DROP FOREIGN KEY spamreport_ibfk_2;
76-- ALTER TABLE SpamVerdict DROP FOREIGN KEY spamverdict_ibfk_2;
77
78-- This ID is the first comment entered that was stored in CommentContent only.
79-- CALL CopyNewCommentContentBackToComment(31459489, 40 * 1000000, 5000);
80
81-- Add back foreign key constraints.
82-- ALTER TABLE SpamReport ADD FOREIGN KEY (comment_id) REFERENCES Comment(id);
83-- ALTER TABLE SpamVerdict ADD FOREIGN KEY (comment_id) REFERENCES Comment(id);