Koha/installer/data/mysql/db_revs/221200026.pl
Tomas Cohen Arazi f1346c2025
Bug 21983: DB update
This patch:
- Adds a illrequests.deleted_biblio_id column
- Adjusts existing db_rev so people upgrading have the biblio_id value
  moved to the also created column, before attempting to add the FK
  constraint on the biblios table.
- Adds a new db_rev for those who unfortunately already updated, it
  should be idempotent.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-06-09 12:04:48 -03:00

40 lines
1.5 KiB
Perl
Executable file

use Modern::Perl;
return {
bug_number => "22440",
description => "Add new /ill_requests endopoint",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
unless ( column_exists( 'illrequests', 'deleted_biblio_id' ) ) {
$dbh->do(q{
ALTER TABLE illrequests
ADD COLUMN `deleted_biblio_id` int(11) DEFAULT NULL COMMENT 'Deleted bib linked to request'
AFTER `biblio_id`;
});
say $out "Added column 'illrequests.deleted_biblio_id'";
}
# Move deleted biblio_id to deleted_biblio_id before setting the FK
$dbh->do(q{
UPDATE illrequests
LEFT JOIN biblio
ON illrequests.biblio_id=biblio.biblionumber
SET illrequests.biblio_id=NULL,
illrequests.deleted_biblio_id=illrequests.biblio_id
WHERE biblio.biblionumber IS NULL
AND illrequests.biblio_id IS NOT NULL
});
unless ( foreign_key_exists( 'illrequests', 'illrequests_bibfk' ) ) {
$dbh->do(q{
ALTER TABLE illrequests
ADD KEY `illrequests_bibfk` (`biblio_id`),
ADD FOREIGN KEY illrequests_bibfk (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE;
});
say $out "Added foreign key constraint 'illrequests.illrequests_bibfk'";
}
},
};