Skip to content

Commit

Permalink
feat: add fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomiguelpinto committed Feb 19, 2025
1 parent 4518fce commit 80c1330
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class FixInvoicesWithIncorrectTotalPaidAmount < ActiveRecord::Migration[7.1]
def up
execute <<~SQL
UPDATE invoices
SET total_paid_amount_cents = 0
WHERE id IN (
SELECT invoices.id
FROM invoices
LEFT JOIN payments ON invoices.id = payments.invoice_id
LEFT JOIN invoices_payment_requests ON invoices.id = invoices_payment_requests.invoice_id
WHERE payments.id IS NULL
AND invoices_payment_requests.id IS NULL
AND total_amount_cents > 0
AND invoice_type <> 4
AND total_amount_cents = total_paid_amount_cents
AND payment_status = 1
);
SQL
end

def down
end
end

0 comments on commit 80c1330

Please sign in to comment.