Bugzilla – Attachment 49723 Details for
Bug 16170
Pseudo foreign key in Items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16170: Pseudo foreign key in Items
Bug-16170-Pseudo-foreign-key-in-Items.patch (text/plain), 3.85 KB, created by
Marcel de Rooy
on 2016-03-31 06:44:37 UTC
(
hide
)
Description:
Bug 16170: Pseudo foreign key in Items
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2016-03-31 06:44:37 UTC
Size:
3.85 KB
patch
obsolete
>From 87ffc5a0050fa429d4c1294bf32753b1f5c9ce88 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 23 Mar 2016 16:59:26 +0100 >Subject: [PATCH] Bug 16170: Pseudo foreign key in Items >Content-Type: text/plain; charset=utf-8 > >While many of us would like to get rid of biblioitems one day, the current >scheme includes a biblioitemnumber and a biblionumber in Items. >(Which is not so great..) > >But also note that biblionumber is NOT defined as a foreign key in Items, >although a belongs_to relation has been added to the DBIx scheme! >This inconsistency should be resolved. The "remove biblioitem table" >operation is a large one, but in the meantime we better make biblionumber >a regular FK not a 'pseudo' one. > >Note: If in an (very) exceptional case biblionumbers are found in items, >that do not exist in biblio, this patch prints a warning at upgrade >time and does not add the constraint. > >@RM: Please update the DBIx scheme accordingly. > >Test plan: >[1] Run the upgrade. Check if the FK constraint has been added. >[2] Remove the FK constraint. Change the biblionumber of one item to an > unexisting record. Run the upgrade again. Notice the warning. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Tested both cases: constraint added as well as warning printed. > >Signed-off-by: Mark Tompsett <mtompset@hotmail.com> >--- > installer/data/mysql/atomicupdate/16170_dbrev.perl | 25 ++++++++++++++++++++ > installer/data/mysql/kohastructure.sql | 3 ++- > 2 files changed, 27 insertions(+), 1 deletion(-) > create mode 100644 installer/data/mysql/atomicupdate/16170_dbrev.perl > >diff --git a/installer/data/mysql/atomicupdate/16170_dbrev.perl b/installer/data/mysql/atomicupdate/16170_dbrev.perl >new file mode 100644 >index 0000000..7cbfdeb >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/16170_dbrev.perl >@@ -0,0 +1,25 @@ >+my $dbh = C4::Context->dbh; >+my $DBversion = "XXX"; >+ >+# RM: Copy/paste from here, and uncomment >+ >+#if ( CheckVersion($DBversion) ) { >+ # this should normally not be needed, but just in case >+ my ( $cnt ) = $dbh->selectrow_array( q| >+SELECT COUNT(*) FROM items it >+LEFT JOIN biblio bi ON bi.biblionumber=it.biblionumber >+LEFT JOIN biblioitems bii USING (biblioitemnumber) >+WHERE bi.biblionumber IS NULL >+ |); >+ if( $cnt ) { >+ print "WARNING: You have corrupted data in your items table!! The table contains $cnt references to biblio records that do not exist.\nPlease correct your data IMMEDIATELY after this upgrade and manually add the foreign key constraint for biblionumber in the items table.\n"; >+ } else { >+ # now add FK >+ $dbh->do( q| >+ALTER TABLE items >+ADD FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE >+ |); >+ print "Upgrade to $DBversion done (Bug 1xxxx - Add FK for biblionumber in items)\n"; >+ } >+ #SetVersion($DBversion); >+#} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 63fefe7..14a7019 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1282,7 +1282,8 @@ CREATE TABLE `items` ( -- holdings/item information > KEY `itype_idx` (`itype`), > CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblioitemnumber`) REFERENCES `biblioitems` (`biblioitemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `items_ibfk_2` FOREIGN KEY (`homebranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE, >- CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE >+ CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE, >+ CONSTRAINT `items_ibfk_4` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; > > -- >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16170
:
49681
|
49706
|
49707
|
49708
|
49723
|
49724
|
49771
|
49772
|
51096
|
51097
|
51098
|
51099