Bug 17202: (QA follow-up) Add foreign key constraint

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Kyle M Hall 2021-04-23 09:36:03 -04:00 committed by Jonathan Druart
parent e96c8439ff
commit f910772cba
2 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1,12 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
$dbh->do(q{
DELETE FROM collections_tracking WHERE colId NOT IN ( SELECT colId FROM collections )
});
$dbh->do(q{
ALTER TABLE collections_tracking
ADD CONSTRAINT `collectionst_ibfk_1` FOREIGN KEY (`colId`) REFERENCES `collections` (`colId`) ON DELETE CASCADE ON UPDATE CASCADE
});
NewVersion( $DBversion, 17202, "Add FK constraint for collection to collections_tracking");
}

View File

@ -1980,7 +1980,8 @@ CREATE TABLE `collections_tracking` (
`collections_tracking_id` int(11) NOT NULL AUTO_INCREMENT,
`colId` int(11) NOT NULL DEFAULT 0 COMMENT 'collections.colId',
`itemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'items.itemnumber',
PRIMARY KEY (`collections_tracking_id`)
PRIMARY KEY (`collections_tracking_id`),
CONSTRAINT `collectionst_ibfk_1` FOREIGN KEY (`colId`) REFERENCES `collections` (`colId`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;