Bug 38011: Add a foreign key between vendors and subscriptions
Test plan: prove t/db_dependent/Koha/Subscription.t prove t/db_dependent/Koha/Acquisition/Booksellers.t Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Amended-by: Jonathan Druart Rename $rs Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
39fa74f683
commit
54cf322ad1
|
|
@ -74,9 +74,8 @@ Returns the list of subscriptions for the vendor
|
|||
|
||||
sub subscriptions {
|
||||
my ($self) = @_;
|
||||
|
||||
# FIXME FK missing at DB level
|
||||
return Koha::Subscriptions->search( { aqbooksellerid => $self->id } );
|
||||
my $rs = $self->_result->subscriptions;
|
||||
return Koha::Subscriptions->_new_from_dbic($rs);
|
||||
}
|
||||
|
||||
=head3 aliases
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
use Modern::Perl;
|
||||
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
|
||||
|
||||
return {
|
||||
bug_number => "38011",
|
||||
description => "Add missing foreign key to subscription table",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||
|
||||
unless ( foreign_key_exists( 'subscription', 'subscription_ibfk_4' ) ) {
|
||||
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE subscription MODIFY COLUMN aqbooksellerid int(11) DEFAULT NULL COMMENT 'foreign key for aqbooksellers.id to link to the vendor'
|
||||
}
|
||||
);
|
||||
|
||||
$dbh->do(
|
||||
q|
|
||||
ALTER TABLE subscription
|
||||
ADD CONSTRAINT subscription_ibfk_4
|
||||
FOREIGN KEY (aqbooksellerid)
|
||||
REFERENCES aqbooksellers (id) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
|
|
||||
);
|
||||
say_success( $out, "Updated foreign key 'subscription_ibfk_4'" );
|
||||
} else {
|
||||
say_warning( $out, "Foreign key 'subscription_ibfk_4' already exists" );
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
@ -6068,7 +6068,7 @@ CREATE TABLE `subscription` (
|
|||
`subscriptionid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique key for this subscription',
|
||||
`librarian` varchar(100) DEFAULT '' COMMENT 'the librarian''s username from borrowers.userid',
|
||||
`startdate` date DEFAULT NULL COMMENT 'start date for this subscription',
|
||||
`aqbooksellerid` int(11) DEFAULT 0 COMMENT 'foreign key for aqbooksellers.id to link to the vendor',
|
||||
`aqbooksellerid` int(11) DEFAULT NULL COMMENT 'foreign key for aqbooksellers.id to link to the vendor',
|
||||
`cost` int(11) DEFAULT 0,
|
||||
`aqbudgetid` int(11) DEFAULT 0,
|
||||
`weeklength` int(11) DEFAULT 0 COMMENT 'subscription length in weeks (will not be filled in if monthlength or numberlength is set)',
|
||||
|
|
@ -6113,9 +6113,11 @@ CREATE TABLE `subscription` (
|
|||
KEY `subscription_ibfk_1` (`periodicity`),
|
||||
KEY `subscription_ibfk_2` (`numberpattern`),
|
||||
KEY `subscription_ibfk_3` (`biblionumber`),
|
||||
KEY `subscription_ibfk_4` (`aqbooksellerid`),
|
||||
CONSTRAINT `subscription_ibfk_1` FOREIGN KEY (`periodicity`) REFERENCES `subscription_frequencies` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `subscription_ibfk_2` FOREIGN KEY (`numberpattern`) REFERENCES `subscription_numberpatterns` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `subscription_ibfk_3` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
CONSTRAINT `subscription_ibfk_3` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `subscription_ibfk_4` FOREIGN KEY (`aqbooksellerid`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue