Bug 30449: Add missing FK constraint on borrower_attribute_types
Old Koha databases probably have it, newer ones might not. See also BZ description. Test plan: [1} Check SHOW CREATE TABLE borrower_attribute_types to see if you have any index and FK constraint on category_code. [2] Run updatedatabase. [3] If you had category_code_fk, it should be replaced. [4] Remove index and constraint again using things like: alter table borrower_attribute_types drop constraint `borrower_attribute_types_ibfk_1`; alter table borrower_attribute_types drop index category_code; [5] Run updatedatabase. [6] You should have KEY category_code and FK borrower_attribute_types_ibfk_1. [7] Run updatedatabase. Idempotent, no changes. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
7989e661f7
commit
b1bf07f49c
2 changed files with 26 additions and 1 deletions
23
installer/data/mysql/atomicupdate/bug_30449.pl
Executable file
23
installer/data/mysql/atomicupdate/bug_30449.pl
Executable file
|
@ -0,0 +1,23 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => 30449,
|
||||
description => "Check borrower_attribute_types FK constraint",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
|
||||
if( foreign_key_exists('borrower_attribute_types', 'category_code_fk') ) {
|
||||
$dbh->do( q|ALTER TABLE borrower_attribute_types DROP CONSTRAINT category_code_fk| );
|
||||
if( index_exists('borrower_attribute_types', 'category_code_fk') ) {
|
||||
$dbh->do( q|ALTER TABLE borrower_attribute_types DROP INDEX category_code_fk| );
|
||||
}
|
||||
}
|
||||
if( !foreign_key_exists('borrower_attribute_types', 'borrower_attribute_types_ibfk_1') ) {
|
||||
if( !index_exists('borrower_attribute_types', 'category_code') ) {
|
||||
$dbh->do( q|ALTER TABLE borrower_attribute_types ADD INDEX category_code (category_code)| );
|
||||
}
|
||||
$dbh->do( q|ALTER TABLE borrower_attribute_types ADD CONSTRAINT borrower_attribute_types_ibfk_1 FOREIGN KEY (`category_code`) REFERENCES `categories` (`categorycode`)| );
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1124,7 +1124,9 @@ CREATE TABLE `borrower_attribute_types` (
|
|||
`keep_for_pseudonymization` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 for no)',
|
||||
`mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not',
|
||||
PRIMARY KEY (`code`),
|
||||
KEY `auth_val_cat_idx` (`authorised_value_category`)
|
||||
KEY `auth_val_cat_idx` (`authorised_value_category`),
|
||||
KEY `category_code` (`category_code`),
|
||||
CONSTRAINT `borrower_attribute_types_ibfk_1` FOREIGN KEY (`category_code`) REFERENCES `categories` (`categorycode`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
|
Loading…
Reference in a new issue