@@ -, +, @@ auth_subfield_structure.authtypecode SELECT COUNT(*) FROM auth_subfield_structure WHERE authtypecode='RM_ME'; --- installer/data/mysql/kohastructure.sql | 3 ++- installer/data/mysql/updatedatabase.pl | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -58,7 +58,8 @@ CREATE TABLE `auth_subfield_structure` ( `frameworkcode` varchar(10) NOT NULL default '', `defaultvalue` TEXT DEFAULT '', PRIMARY KEY (`authtypecode`,`tagfield`,`tagsubfield`), - KEY `tab` (`authtypecode`,`tab`) + KEY `tab` (`authtypecode`,`tab`), + CONSTRAINT `auth_subfield_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -9902,6 +9902,24 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.19.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + DELETE ass.* + FROM auth_subfield_structure AS ass + LEFT JOIN auth_types USING(authtypecode) + WHERE auth_types.authtypecode IS NULL + }); + + $dbh->do(q{ + ALTER TABLE auth_subfield_structure + ADD CONSTRAINT auth_subfield_structure_ibfk_1 FOREIGN KEY (authtypecode) REFERENCES auth_types(authtypecode) ON DELETE CASCADE ON UPDATE CASCADE + }); + + print "Upgrade to $DBversion done (Bug 8480 - Add foreign key on auth_subfield_structure.authtypecode)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --