From 17499fbf06060495e0cd209500ba6999db34e956 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 4 Oct 2023 15:53:41 -0400 Subject: [PATCH] Bug 30719: Atomic update fixes Signed-off-by: Tomas Cohen Arazi --- .../atomicupdate/bug_30719_add_ill_batches.pl | 94 ++++++++++--------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl b/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl index c3a378b69c..76329b35dd 100755 --- a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl +++ b/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl @@ -2,39 +2,49 @@ use Modern::Perl; return { bug_number => "30719", - description => "Add ILL batches", + description => "Add ability to create batch ILL requests", up => sub { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; - $dbh->do( - q{ - CREATE TABLE IF NOT EXISTS `illbatch_statuses` ( - `id` int(11) NOT NULL auto_increment COMMENT "Status ID", - `name` varchar(100) NOT NULL COMMENT "Name of status", - `code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status", - `is_system` tinyint(1) COMMENT "Is this status required for system operation", - PRIMARY KEY (`id`), - UNIQUE KEY `u_illbatchstatuses__code` (`code`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + + unless ( TableExists('illbatch_statuses') ) { + $dbh->do( + q{ + CREATE TABLE`illbatch_statuses` ( + `id` int(11) NOT NULL auto_increment COMMENT "Status ID", + `name` varchar(100) NOT NULL COMMENT "Name of status", + `code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status", + `is_system` tinyint(1) COMMENT "Is this status required for system operation", + PRIMARY KEY (`id`), + UNIQUE KEY `u_illbatchstatuses__code` (`code`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + } + ); + + say $out "Added new table 'illbatch_statuses'"; } - ); - $dbh->do( - q{ - CREATE TABLE IF NOT EXISTS `illbatches` ( - `id` int(11) NOT NULL auto_increment COMMENT "Batch ID", - `name` varchar(100) NOT NULL COMMENT "Unique name of batch", - `backend` varchar(20) NOT NULL COMMENT "Name of batch backend", - `borrowernumber` int(11) COMMENT "Patron associated with batch", - `branchcode` varchar(50) COMMENT "Branch associated with batch", - `statuscode` varchar(20) COMMENT "Status of batch", - PRIMARY KEY (`id`), - UNIQUE KEY `u_illbatches__name` (`name`), - CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + + unless ( TableExists('illbatches') ) { + $dbh->do( + q{ + CREATE TABLE `illbatches` ( + `id` int(11) NOT NULL auto_increment COMMENT "Batch ID", + `name` varchar(100) NOT NULL COMMENT "Unique name of batch", + `backend` varchar(20) NOT NULL COMMENT "Name of batch backend", + `borrowernumber` int(11) COMMENT "Patron associated with batch", + `branchcode` varchar(50) COMMENT "Branch associated with batch", + `statuscode` varchar(20) COMMENT "Status of batch", + PRIMARY KEY (`id`), + UNIQUE KEY `u_illbatches__name` (`name`), + CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + } + ); + + say $out "Added new table 'illbatches'"; } - ); unless ( column_exists( 'illrequests', 'batch_id' ) ) { $dbh->do( q{ @@ -42,6 +52,8 @@ return { ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to } ); + + say $out "Added column 'illrequests.batch_id'"; } unless ( foreign_key_exists( 'illrequests', 'illrequests_ibfk' ) ) { @@ -87,15 +99,13 @@ return { | ); - if ($new_status) { - say $out "Bug 30719: NEW ILL batch status found. Update has already been run."; - } else { + unless ($new_status) { $dbh->do( qq{ INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES ('New', 'NEW', '1') } ); - say $out "Bug 30719: Added NEW ILL batch status"; + say $out "Added new ILL batch status 'NEW'"; } # Get any existing IN_PROGRESS batch status @@ -105,15 +115,13 @@ return { | ); - if ($in_progress_status) { - say $out "Bug 30719: IN_PROGRESS ILL batch status found. Update has already been run."; - } else { + unless ($in_progress_status) { $dbh->do( qq{ INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'In progress', 'IN_PROGRESS', '1' ) } ); - say $out "Bug 30719: Added IN_PROGRESS ILL batch status"; + say $out "Added new ILL batch status 'IN_PROGRESS'"; } # Get any existing COMPLETED batch status @@ -123,15 +131,13 @@ return { | ); - if ($completed_status) { - say $out "Bug 30719: COMPLETED ILL batch status found. Update has already been run."; - } else { + unless ($completed_status) { $dbh->do( qq{ INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Completed', 'COMPLETED', '1' ) } ); - say $out "Bug 30719: Added COMPLETED ILL batch status"; + say $out "Added new ILL batch status 'COMPLETED'"; } # Get any existing UNKNOWN batch status @@ -141,17 +147,13 @@ return { | ); - if ($unknown_status) { - say $out "Bug 30719: UNKNOWN ILL batch status found. Update has already been run."; - } else { + unless ($unknown_status) { $dbh->do( qq{ INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Unknown', 'UNKNOWN', '1' ) } ); - say $out "Bug 30719: Added UNKNOWN ILL batch status"; + say $out "Added new ILL batch status 'UNKNOWN'"; } - - say $out "Bug 30719: Add ILL batches completed"; }, }; -- 2.39.5