From c14cabd87da4626e54814ce2b49fda4cf3798ffb Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Tue, 13 Aug 2024 10:07:30 +0000 Subject: [PATCH] Bug 37601: Add status field to bookings table Signed-off-by: LEBSimonsen Signed-off-by: Martin Renvoize --- ...7601-add-status-field-to-bookings-table.pl | 28 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + 2 files changed, 29 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_37601-add-status-field-to-bookings-table.pl diff --git a/installer/data/mysql/atomicupdate/bug_37601-add-status-field-to-bookings-table.pl b/installer/data/mysql/atomicupdate/bug_37601-add-status-field-to-bookings-table.pl new file mode 100644 index 00000000000..24789a9f723 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_37601-add-status-field-to-bookings-table.pl @@ -0,0 +1,28 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_failure say_success say_info); + +return { + bug_number => '37601', + description => 'Add status column to bookings table', + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @{$args}{qw(dbh out)}; + + if ( column_exists( 'bookings', 'status' ) ) { + say_info( $out, q{Column 'status' already exists in 'bookings' table. Skipping...} ); + + return; + } + + my $after = 'AFTER' . ( column_exists( 'bookings', 'updated_at' ) ? q{`updated_at`} : q{`end_date`} ); + my $statement = <<~"SQL"; + ALTER TABLE `bookings` + ADD COLUMN `status` ENUM('created', 'cancelled') NOT NULL DEFAULT 'created' COMMENT 'current status of the booking' $after; + SQL + if ( $dbh->do($statement) ) { + say_success( $out, q{Added column 'bookings.status'} ); + } else { + say_failure( $out, q{Failed to add column 'bookings.status'} ); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index f3dd950328d..cd535365722 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1217,6 +1217,7 @@ CREATE TABLE `bookings` ( `pickup_library_id` varchar(10) NOT NULL COMMENT 'Identifier for booking pickup library', `start_date` datetime DEFAULT NULL COMMENT 'the start date of the booking', `end_date` datetime DEFAULT NULL COMMENT 'the end date of the booking', + `status` enum('created', 'cancelled') NOT NULL DEFAULT 'created' COMMENT 'current status of the booking', PRIMARY KEY (`booking_id`), KEY `patron_id` (`patron_id`), KEY `biblio_id` (`biblio_id`), -- 2.46.0