Bugzilla – Attachment 33242 Details for
Bug 13007
suggestions.budgetid should be a foreign key
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13007: Add a foreign key for suggestions.budgetid
Bug-13007-Add-a-foreign-key-for-suggestionsbudgeti.patch (text/plain), 3.49 KB, created by
Jonathan Druart
on 2014-11-05 10:50:33 UTC
(
hide
)
Description:
Bug 13007: Add a foreign key for suggestions.budgetid
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-11-05 10:50:33 UTC
Size:
3.49 KB
patch
obsolete
>From 34584993f847e5575e9cfdec533c8946dffeb1f6 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Mon, 29 Sep 2014 16:16:23 +0200 >Subject: [PATCH] Bug 13007: Add a foreign key for suggestions.budgetid > >The DB field suggestions.budgetid should be linked to >aqbudgets.budget_id. > >If the fund is removed, this column should be set to NULL. > >Test plan: >1/ Using your SQL CLI (or equivalent), create or update 1+ suggestions and >set "0" in the budgetid field (or a nonexistent budget id). >2/ Execute the updatedabase script. >3/ Verify that your suggestion is unlinked to the nonexistent fund. >4/ Verify the constraint has correctly been added (show create table >suggestions). >5/ Check that this change does not affect the behavior on adding a >suggestion (linked to a fund or not). >--- > installer/data/mysql/kohastructure.sql | 3 ++- > installer/data/mysql/updatedatabase.pl | 20 ++++++++++++++++++++ > t/db_dependent/Suggestions.t | 1 + > 3 files changed, 23 insertions(+), 1 deletion(-) > >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 865f930..b13336e 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2188,7 +2188,8 @@ CREATE TABLE `suggestions` ( -- purchase suggestions > total DECIMAL(28,6) default NULL, -- suggested total cost (price*quantity updated for currency) > PRIMARY KEY (`suggestionid`), > KEY `suggestedby` (`suggestedby`), >- KEY `managedby` (`managedby`) >+ KEY `managedby` (`managedby`), >+ CONSTRAINT `suggestions_budget_id_fk` FOREIGN KEY (`budgetid`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE SET NULL ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8; > > -- >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 078a9f3..5ba7952 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -8974,6 +8974,26 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { > SetVersion($DBversion); > } > >+$DBversion = "3.17.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do(q| >+ UPDATE suggestions s SET s.budgetid = NULL >+ WHERE NOT EXISTS ( >+ SELECT NULL >+ FROM aqbudgets b >+ WHERE b.budget_id = s.budgetid >+ ); >+ |); >+ >+ $dbh->do(q| >+ ALTER TABLE suggestions >+ ADD CONSTRAINT suggestions_budget_id_fk FOREIGN KEY (budgetid) REFERENCES aqbudgets(budget_id) ON DELETE SET NULL ON UPDATE CASCADE >+ |); >+ >+ print "Upgrade to $DBversion done (Bug 13007 - Add new foreign key suggestions.budgetid)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index 299bdf6..b4bbd02 100644 >--- a/t/db_dependent/Suggestions.t >+++ b/t/db_dependent/Suggestions.t >@@ -78,6 +78,7 @@ is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestio > is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' ); > is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' ); > is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' ); >+is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' ); > > is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); > >-- >2.1.0
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 13007
:
31924
|
31945
|
33241
|
33242
|
33643
|
33644
|
33651
|
33653
|
33807
|
33808
|
35601
|
35602