From 550ac77bfd0194d8b00fb79b5a4591ba3d76be30 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 8 Nov 2012 13:54:47 +0100 Subject: [PATCH] Bug 9030: Add constraint on aqorders_items.ordernumber Signed-off-by: Kyle M Hall Passed-QA-by: Marcel de Rooy Signed-off-by: Jared Camins-Esakov --- installer/data/mysql/kohastructure.sql | 3 ++- installer/data/mysql/updatedatabase.pl | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index cc9fb21e1d..c40ba6fe80 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2824,7 +2824,8 @@ CREATE TABLE `aqorders_items` ( -- information on items entered in the acquisiti `itemnumber` int(11) NOT NULL, -- the item number for this item (items.itemnumber) `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order item was last touched PRIMARY KEY (`itemnumber`), - KEY `ordernumber` (`ordernumber`) + KEY `ordernumber` (`ordernumber`), + CONSTRAINT aqorders_items_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 966ec9bbdc..3eb95c4ebd 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6083,6 +6083,20 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q{ + DELETE from aqorders_items where ordernumber NOT IN (SELECT ordernumber FROM aqorders); + }); + $dbh->do(q{ + ALTER TABLE aqorders_items + ADD CONSTRAINT aqorders_items_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) + ON DELETE CASCADE ON UPDATE CASCADE; + }); + print "Upgrade to $DBversion done (Bug 9030: Add constraint on aqorders_items.ordernumber)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) -- 2.39.5