From 0846e45a1e45da588ddfdb32322afb69934d1a89 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 Signed-off-by: Katrin Fischer --- ...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 0000000000..24789a9f72 --- /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 0ac5919d3a..9a3661df15 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1219,6 +1219,7 @@ CREATE TABLE `bookings` ( `end_date` datetime DEFAULT NULL COMMENT 'the end date of the booking', `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('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.39.5