Maybe just cherry-pick this particular commit and add it to your JSON API pull request?  Probably after removing the unnecessary "CREATE INDEX invoices_paid_timestamp".  Then I'll just put the "not set `pay_index` if not PAID" in a separate pull request.