Bug 26993: Database updates

Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Lucas Gass 2025-09-22 21:39:58 +00:00
parent 88e07a074e
commit 0fc32b7de8
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
return {
bug_number => "26993",
description => "Remove unique constraint on itemnumber in items_last_borrower to allow multiple borrowers per item",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
# Drop the foreign key constraint temporarily
if ( index_exists( 'items_last_borrower', 'itemnumber' ) ) {
$dbh->do(
q{
ALTER TABLE items_last_borrower
DROP FOREIGN KEY items_last_borrower_ibfk_1
}
);
# Drop the unique index
$dbh->do(
q{
ALTER TABLE items_last_borrower DROP INDEX itemnumber
}
);
# Put the FK constraint back, without itemnumber having to be unique
$dbh->do(
q{
ALTER TABLE items_last_borrower
ADD CONSTRAINT items_last_borrower_ibfk_1
FOREIGN KEY (itemnumber) REFERENCES items (itemnumber)
ON DELETE CASCADE ON UPDATE CASCADE
}
);
say_success( $out, "Adjusted foreign key constraints on items_last_borrower table" );
}
# Update system preference from YesNo to Integer
$dbh->do(
q{
UPDATE systempreferences
SET type = 'integer',
explanation = 'Defines the number of borrowers stored per item in the items_last_borrower table'
WHERE variable = 'StoreLastBorrower'
}
);
say_success( $out, "Updated StoreLastBorrower system preference to accept numeric values" );
},
};