From fb3a28ef24b1666234a1ba482644bf686baadd58 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Thu, 17 Oct 2024 11:52:28 +0000 Subject: [PATCH] Bug 38193: Add cancellation_reason field to bookings table MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Sponsored-by: Büchereizentrale Schleswig-Holstein Signed-off-by: Thibaud Guillot Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- api/v1/swagger/definitions/booking.yaml | 5 ++++ ...ellation_reason_field_to_bookings_table.pl | 27 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + 3 files changed, 33 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_38193-add_cancellation_reason_field_to_bookings_table.pl diff --git a/api/v1/swagger/definitions/booking.yaml b/api/v1/swagger/definitions/booking.yaml index b40330dcd5..0ca253c23b 100644 --- a/api/v1/swagger/definitions/booking.yaml +++ b/api/v1/swagger/definitions/booking.yaml @@ -10,6 +10,11 @@ properties: booking_id: description: Internal booking identifier type: integer + cancellation_reason: + description: Booking cancellation reason + type: + - string + - "null" creation_date: description: Creation date and time of this booking readOnly: true diff --git a/installer/data/mysql/atomicupdate/bug_38193-add_cancellation_reason_field_to_bookings_table.pl b/installer/data/mysql/atomicupdate/bug_38193-add_cancellation_reason_field_to_bookings_table.pl new file mode 100755 index 0000000000..58ef34c759 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_38193-add_cancellation_reason_field_to_bookings_table.pl @@ -0,0 +1,27 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_failure say_success say_info); + +return { + bug_number => '38193', + description => 'Add cancellation_reason field to bookings table', + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @{$args}{qw(dbh out)}; + + if ( column_exists( 'bookings', 'cancellation_reason' ) ) { + say_info( $out, q{Column 'cancellation_reason' already exists in 'bookings' table. Skipping...} ); + + return; + } + + my $statement = <<~"SQL"; + ALTER TABLE `bookings` + ADD COLUMN `cancellation_reason` varchar(80) DEFAULT NULL COMMENT 'optional authorised value BOOKING_CANCELLATION' AFTER `status`; + SQL + if ( $dbh->do($statement) ) { + say_success( $out, q{Added column 'bookings.cancellation_reason'} ); + } else { + say_failure( $out, q{Failed to add column 'bookings.cancellation_reason'} ); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 31f0828a24..74c97bfa5d 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1220,6 +1220,7 @@ CREATE TABLE `bookings` ( `creation_date` timestamp DEFAULT current_timestamp() COMMENT 'the timestamp for when a booking was created', `modification_date` timestamp DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'the timestamp for when a booking has been updated', `status` enum('new', 'cancelled', 'completed') NOT NULL DEFAULT 'new' COMMENT 'current status of the booking', + `cancellation_reason` varchar(80) DEFAULT NULL COMMENT 'optional authorised value BOOKING_CANCELLATION', PRIMARY KEY (`booking_id`), KEY `patron_id` (`patron_id`), KEY `biblio_id` (`biblio_id`), -- 2.39.5