Bug 27944: (QA follow-up) Make atomic update idempotent

This patch checks the DB structure to see if the status column
definition contains 'REQUESTED' as a valid ENUM value.

The script is also moved into the new style.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2021-09-22 14:42:28 -03:00 committed by Jonathan Druart
parent f9078f2a00
commit 504deebdfc
2 changed files with 40 additions and 31 deletions

View File

@ -0,0 +1,40 @@
use Modern::Perl;
return {
bug_number => "27944",
description => "Add REQUESTED as enum element for status column, move AR_PENDING letter to AR_REQUESTED, and add new AR_PENDING letter",
up => sub {
my ($args) = @_;
my ($dbh) = @$args{qw(dbh)};
# check if we already added the REQUESTED type in ENUM
my @row = $dbh->selectrow_array(q{
SHOW COLUMNS FROM article_requests WHERE Field='status' AND Type LIKE "%'REQUESTED'%";
});
unless (@row) {
$dbh->do(q{
ALTER TABLE `article_requests`
MODIFY `status` enum('REQUESTED', 'PENDING','PROCESSING','COMPLETED','CANCELED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'REQUESTED'
});
$dbh->do(q{
UPDATE article_requests
SET status='REQUESTED' WHERE status='PENDING'
});
$dbh->do(q{
UPDATE `letter`
SET `code` = 'AR_REQUESTED',
`name` = REPLACE(name, '- open', '- new')
WHERE `module` = 'circulation'
AND `code` = 'AR_PENDING'
})
if ( $dbh->selectrow_array('SELECT COUNT(*) FROM letter WHERE code=?', undef, 'AR_REQUESTED') )[0] == 0; # Check to make idempotent
$dbh->do(q{
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`) VALUES
('circulation', 'AR_PENDING', '', 'Article request - pending', 0, 'Pending article request', 'Dear <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)\r\n\r\nYour request for an article from <<biblio.title>> (<<items.barcode>>) is now in pending state.\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n\r\n\r\nThank you!', 'email')
});
}
},
}

View File

@ -1,31 +0,0 @@
$DBversion = 'XXX'; # will be replaced by the RM
if ( CheckVersion($DBversion) ) {
# you can use $dbh here like:
$dbh->do(
"ALTER TABLE `article_requests` MODIFY `status` enum('REQUESTED', 'PENDING','PROCESSING','COMPLETED','CANCELED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'REQUESTED'"
);
$dbh->do(q|UPDATE article_requests SET status='REQUESTED' WHERE status='PENDING'|);
$dbh->do(
q{
UPDATE `letter`
SET `code` = 'AR_REQUESTED',
`name` = REPLACE(name, '- open', '- new')
WHERE `module` = 'circulation'
AND `code` = 'AR_PENDING'
}
) if ( $dbh->selectrow_array('SELECT COUNT(*) FROM letter WHERE code=?', undef, 'AR_REQUESTED') )[0] == 0; # Check to make idempotent
$dbh->do(
q{
INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`) VALUES
('circulation', 'AR_PENDING', '', 'Article request - pending', 0, 'Pending article request', 'Dear <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)\r\n\r\nYour request for an article from <<biblio.title>> (<<items.barcode>>) is now in pending state.\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n\r\n\r\nThank you!', 'email')
}
);
# Always end with this (adjust the bug info)
NewVersion( $DBversion, 27944,
"Add REQUESTED as enum element for status column, move AR_PENDING letter to AR_REQUESTED, and add new AR_PENDING letter"
);
}