+ # For cust_pay_pending records linked to voided payments, move the paynum
+ # to void_paynum.
+ $sql =
+ "UPDATE cust_pay_pending SET void_paynum = paynum, paynum = NULL
+ WHERE paynum IS NOT NULL AND void_paynum IS NULL AND EXISTS(
+ SELECT 1 FROM cust_pay_void
+ WHERE cust_pay_void.paynum = cust_pay_pending.paynum
+ ) AND NOT EXISTS(
+ SELECT 1 FROM cust_pay
+ WHERE cust_pay.paynum = cust_pay_pending.paynum
+ )";
+ $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+
+}
+
+sub _upgrade_schema {
+ my ($class, %opts) = @_;
+
+ # fix records where jobnum points to a nonexistent queue job
+ my $sql = 'UPDATE cust_pay_pending SET jobnum = NULL
+ WHERE NOT EXISTS (
+ SELECT 1 FROM queue WHERE queue.jobnum = cust_pay_pending.jobnum
+ )';
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+ '';