diff options
author | Ivan Kohler <ivan@freeside.biz> | 2017-02-14 09:02:49 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2017-02-14 09:02:49 -0800 |
commit | 07dee094cc143a19acc4bc16b00361b1e23a739f (patch) | |
tree | 7a4eaa38f4ef1e795d951fb5d3ce7bfbbc581dbc | |
parent | 2b2111e072ce91322705e21215c55652d271e4ba (diff) |
fix FK upgrade for pkg_referral: remove records referencing non-existant customer packages
-rw-r--r-- | FS/FS/pkg_referral.pm | 15 |
1 files changed, 14 insertions, 1 deletions
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 |