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 COLLATE=utf8_unicode_ci;
--
SetVersion($DBversion);
}
+$DBversion = "3.19.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)
use Koha::DateUtils qw( dt_from_string );
-use Test::More tests => 101;
+use Test::More tests => 102;
use Test::Warn;
BEGIN {
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
is( $suggestion->{managedby}, undef, 'NewSuggestion stores empty string as undef for non existent foreign key (integer)' );
is( $suggestion->{manageddate}, undef, 'NewSuggestion stores empty string as undef for date' );
+is( $suggestion->{budgetid}, undef, 'NewSuggestion should set budgetid to NULL if not given' );
+
is( CountSuggestion('ASKED'), 2, 'CountSuggestion returns the correct number of suggestions' );