From: Ivan Kohler Date: Tue, 14 Feb 2017 17:02:48 +0000 (-0800) Subject: fix FK upgrade for pkg_referral: remove records referencing non-existant customer... X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=877a4eb85cb847bd314d6a9192fedb1dc35c5d02 fix FK upgrade for pkg_referral: remove records referencing non-existant customer packages --- diff --git a/FS/FS/pkg_referral.pm b/FS/FS/pkg_referral.pm index 333c2bf8a..a5ac79505 100644 --- a/FS/FS/pkg_referral.pm +++ b/FS/FS/pkg_referral.pm @@ -2,7 +2,7 @@ package FS::pkg_referral; use strict; use vars qw( @ISA ); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( dbh ); @ISA = qw(FS::Record); @@ -108,6 +108,19 @@ sub check { $self->SUPER::check; } +sub _upgrade_schema { + my ($class, %opts) = @_; + + my $sql = ' + DELETE FROM pkg_referral WHERE NOT EXISTS + ( SELECT 1 FROM cust_pkg WHERE cust_pkg.pkgnum = pkg_referral.pkgnum ) + '; + + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + ''; +} + =back =head1 BUGS