From a4409568b39a9fc0d3edd3606e30c40da8c8c4d0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 18 Oct 2022 09:48:59 -0300 Subject: [PATCH] Bug 31626: (QA follow-up) Make db_rev robust Signed-off-by: Tomas Cohen Arazi --- installer/data/mysql/atomicupdate/bug_31626.pl | 14 +++++++++----- installer/data/mysql/kohastructure.sql | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_31626.pl b/installer/data/mysql/atomicupdate/bug_31626.pl index d02b3a88b1..e577e65829 100755 --- a/installer/data/mysql/atomicupdate/bug_31626.pl +++ b/installer/data/mysql/atomicupdate/bug_31626.pl @@ -6,10 +6,14 @@ return { up => sub { my ($args) = @_; my ($dbh, $out) = @$args{qw(dbh out)}; - $dbh->do(q{ - ALTER TABLE message_queue - ADD COLUMN letter_id INT(11) NULL DEFAULT NULL AFTER message_id, - ADD CONSTRAINT letter_fk FOREIGN KEY (letter_id) REFERENCES letter(id) ON DELETE SET NULL ON UPDATE CASCADE - }); + unless ( column_exists( 'message_queue', 'letter_id' ) ) { + $dbh->do(q{ + ALTER TABLE message_queue + ADD COLUMN `letter_id` int(11) DEFAULT NULL COMMENT 'Foreign key to the letters table' AFTER message_id, + ADD CONSTRAINT letter_fk FOREIGN KEY (letter_id) REFERENCES letter(id) ON DELETE SET NULL ON UPDATE CASCADE + }); + + say $out "Added 'letter_id' column to 'message_queue' table"; + } }, }; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 37f8ca7353..b0dea05b7b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3847,7 +3847,7 @@ DROP TABLE IF EXISTS `message_queue`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `message_queue` ( `message_id` int(11) NOT NULL AUTO_INCREMENT, - `letter_id` int(11) DEFAULT NULL, + `letter_id` int(11) DEFAULT NULL COMMENT 'Foreign key to the letters table', `borrowernumber` int(11) DEFAULT NULL, `subject` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, `content` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- 2.39.5