blob: ecd58c5cb1f5f2ee3bebf1cbee5e6c30e3e99f39 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001-- 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.
Copybara854996b2021-09-07 19:36:02 +00004
5
6DROP PROCEDURE IF EXISTS CopyNewCommentContentBackToComment;
7
8delimiter //
9
10CREATE PROCEDURE CopyNewCommentContentBackToComment(
11 IN in_start INT, IN in_stop INT, IN in_step INT)
12BEGIN
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 content MEDIUMTEXT COLLATE utf8mb4_unicode_ci,
32 inbound_message MEDIUMTEXT COLLATE utf8mb4_unicode_ci,
33 deleted_by INT UNSIGNED,
34 is_spam BOOLEAN DEFAULT FALSE,
35 is_description BOOLEAN DEFAULT FALSE,
36
37 PRIMARY KEY(id)
38 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
39
40
41 INSERT INTO temp_comment
42 SELECT Comment.id, Comment.issue_id, Comment.created, Comment.project_id,
43 Comment.commenter_id, CommentContent.content,
44 CommentContent.inbound_message, Comment.deleted_by, Comment.is_spam,
45 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 content, inbound_message, deleted_by, is_spam, is_description)
54 SELECT id, issue_id, created, project_id, commenter_id,
55 content, inbound_message, deleted_by, is_spam, is_description
56 FROM temp_comment;
57
58 SET in_start = in_start + in_step;
59
60 END LOOP;
61
62END;
63
64
65//
66
67
68delimiter ;
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-- This ID is the first comment entered that was stored in CommentContent only.
77-- CALL CopyNewCommentContentBackToComment(31459489, 40 * 1000000, 5000);
78
79-- Add back foreign key constraints.
80-- ALTER TABLE SpamReport ADD FOREIGN KEY (comment_id) REFERENCES Comment(id);
81-- ALTER TABLE SpamVerdict ADD FOREIGN KEY (comment_id) REFERENCES Comment(id);