From 4633d3793187e2b41799f8eb8fd695a2cede1a62 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 8 Jun 2026 15:05:37 +0100 Subject: [PATCH] Bug 41898: Add atomicupdate and update schema for 'issued' booking status Extends bookings.status enum to ('new', 'cancelled', 'issued', 'completed'). Migrates existing data intelligently: rows with an active checkout in the issues table (via booking_id) are updated to 'issued'; rows whose item has already been returned retain 'completed', which is already correct under the new scheme where 'completed' means the booking was fully fulfilled and the item returned. Sponsored-by: OpenFifth Sponsored-by: Westminster City Council Signed-off-by: Hannah Dunne-Howrie Signed-off-by: Paul Derscheid Signed-off-by: Pedro Amorim --- .../data/mysql/atomicupdate/bug_41898.pl | 42 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_41898.pl diff --git a/installer/data/mysql/atomicupdate/bug_41898.pl b/installer/data/mysql/atomicupdate/bug_41898.pl new file mode 100755 index 0000000000..3a62e015f2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_41898.pl @@ -0,0 +1,42 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_success say_info); + +return { + bug_number => '41898', + description => "Introduce 'issued' booking status and repurpose 'completed' for post-return", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @{$args}{qw(dbh out)}; + + # Extend the enum to include the new 'issued' value. + # Existing 'completed' rows remain valid during migration below. + $dbh->do( + q{ + ALTER TABLE `bookings` + MODIFY COLUMN `status` + ENUM('new', 'cancelled', 'issued', 'completed') NOT NULL DEFAULT 'new' + COMMENT 'current status of the booking' + } + ); + say_success( $out, "Updated 'bookings.status' enum to include 'issued'" ); + + # In the old scheme 'completed' meant the item had been checked out. + # Migrate those rows intelligently: + # - bookings with an active checkout (in issues) → 'issued' + # - bookings whose item has already been returned → 'completed' (unchanged, + # which is correct under the new scheme where 'completed' means returned) + my $updated = $dbh->do( + q{ + UPDATE bookings b + INNER JOIN issues i ON i.booking_id = b.booking_id + SET b.status = 'issued' + WHERE b.status = 'completed' + } + ); + say_success( $out, "Migrated $updated 'completed' bookings to 'issued' (item still on loan)" ); + say_info( + $out, + "Remaining 'completed' bookings represent returned items and are correctly classified" + ); + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 51dfa90e4e..ec250ffad0 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1230,7 +1230,7 @@ CREATE TABLE `bookings` ( `end_date` datetime DEFAULT NULL COMMENT 'the end date of the booking', `creation_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the timestamp for when a booking was created', `modification_date` timestamp NOT NULL 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', + `status` enum('new','cancelled','issued','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`),