Bug 17202: (follow-up) Conditionally add FK
[koha.git] / installer / data / mysql / atomicupdate / bug_17202.perl
1 $DBversion = 'XXX'; # will be replaced by the RM
2 if( CheckVersion( $DBversion ) ) {
3     unless( foreign_key_exists( 'collections_tracking', 'collectionst_ibfk_1' ) ) {
4         $dbh->do(q{
5             DELETE FROM collections_tracking WHERE colId NOT IN ( SELECT colId FROM collections )
6         });
7         $dbh->do(q{
8             ALTER TABLE collections_tracking
9             ADD CONSTRAINT `collectionst_ibfk_1` FOREIGN KEY (`colId`) REFERENCES `collections` (`colId`) ON DELETE CASCADE ON UPDATE CASCADE
10         });
11     }
12
13     NewVersion( $DBversion, 17202, "Add FK constraint for collection to collections_tracking");
14 }