Bug 14237: Set course_items.biblionumber in the DBrev

We need to create the new column without the NOT NULL clause, set the
correct values, then add the NOT NULL clause.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-05-07 09:22:50 +02:00
parent 961f477ee2
commit 5b9d11020a
1 changed files with 11 additions and 1 deletions

View File

@ -1,7 +1,17 @@
$DBversion = 'XXX';
if( CheckVersion( $DBversion ) ){
unless( column_exists( 'course_items', 'biblionumber') ) {
$dbh->do(q{ ALTER TABLE course_items ADD `biblionumber` int(11) NOT NULL AFTER `itemnumber` });
$dbh->do(q{ ALTER TABLE course_items ADD `biblionumber` int(11) AFTER `itemnumber` });
$dbh->do(q{
UPDATE course_items
LEFT JOIN items ON items.itemnumber=course_items.itemnumber
SET course_items.biblionumber=items.biblionumber
WHERE items.itemnumber IS NOT NULL
});
$dbh->do(q{ ALTER TABLE course_items MODIFY COLUMN `biblionumber` INT(11) NOT NULL });
$dbh->do(q{ ALTER TABLE course_items ADD CONSTRAINT `fk_course_items_biblionumber` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE });
$dbh->do(q{ ALTER TABLE course_items CHANGE `itemnumber` `itemnumber` int(11) DEFAULT NULL });
}