[Koha-bugs] [Bug 30899] Upgrade sometimes fails at "Upgrade to 21.11.05.004"

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Jun 3 11:52:02 CEST 2022


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30899

--- Comment #7 from Magnus Enger <magnus at libriotech.no> ---
The relevant code in the database update is:

if( foreign_key_exists('borrower_attribute_types', 'category_code_fk') ) {
  $dbh->do( q|ALTER TABLE borrower_attribute_types DROP CONSTRAINT
category_code_fk| );
  ...
}

The database that succeeds had this before the upgrade: 

  PRIMARY KEY (`code`),
  KEY `auth_val_cat_idx` (`authorised_value_category`),
  KEY `category_code_fk` (`category_code`),
  CONSTRAINT `category_code_fk` FOREIGN KEY (`category_code`) REFERENCES
`categories` (`categorycode`)

And the one that fails had:

  PRIMARY KEY (`code`),
  KEY `auth_val_cat_idx` (`authorised_value_category`)

C4::Installer::foreign_key_exists looks like this

 648 sub foreign_key_exists {
 649     my ( $table_name, $constraint_name ) = @_;
 650     my $dbh = C4::Context->dbh;
 651     my (undef, $infos) = $dbh->selectrow_array(qq|SHOW CREATE TABLE
$table_name|);
 652     return $infos =~ m|CONSTRAINT `$constraint_name` FOREIGN KEY|;
 653 }

Looks to me like the "if" above should prevent the "ALTER TABLE
borrower_attribute_types DROP CONSTRAINT category_code_fk" from being run
against the database at all?

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.


More information about the Koha-bugs mailing list