Bug 30276: (bug 30060 follow-up) Fix 21.12.00.016

ERROR 1832 (HY000): Cannot change column 'code': used in a foreign key constraint 'user_permissions_ibfk_2'

Test plan:
Checkout a commit prior to 30060 (c023f63abc)
reset_all
checkout master+this patch
updatedatabase

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2022-03-28 14:01:26 +02:00 committed by Fridolin Somers
parent bc1c8b4338
commit 563836cce1

View file

@ -21,9 +21,18 @@ return {
$dbh->do(q{ALTER TABLE user_permissions DROP COLUMN temp});
say $out "Removed any duplicate rows";
if ( foreign_key_exists('user_permissions', 'user_permissions_ibfk_2') ) {
$dbh->do(q{
ALTER TABLE user_permissions DROP FOREIGN KEY user_permissions_ibfk_2
});
}
$dbh->do(q{
ALTER TABLE user_permissions ADD CONSTRAINT PK_borrowernumber_module_code PRIMARY KEY (borrowernumber,module_bit,code)
});
$dbh->do(q{
ALTER TABLE user_permissions
ADD CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`) REFERENCES `permissions` (`module_bit`, `code`) ON DELETE CASCADE ON UPDATE CASCADE;
});
say $out "Added a primary key on user_permissions on borrowernumber, module_bit, code";
}
},