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 <https://openfifth.co.uk/>
Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/>
Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
5f99bbb772
commit
4633d37931
|
|
@ -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"
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
@ -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`),
|
||||
|
|
|
|||
Loading…
Reference in New Issue