-- SQL Queries to Reset Loan Payment Data
-- Run these queries in your PostgreSQL database to reset loan payments

-- 1. Reset all loans: Set total_paid to 0 and remaining_balance to loan_amount
UPDATE loans 
SET 
    total_paid = 0,
    remaining_balance = loan_amount
WHERE total_paid > 0;

-- 2. Clear all payment records from the payments table
DELETE FROM payments;

-- 3. Verify the reset (check the results)
SELECT 
    id,
    loan_amount,
    total_paid,
    remaining_balance,
    status
FROM loans
ORDER BY created_at DESC;

-- 4. Check that payments table is empty
SELECT COUNT(*) as payment_count FROM payments;

-- 5. Optional: Reset specific loan by ID (replace 'your-loan-id-here' with actual loan ID)
-- UPDATE loans 
-- SET 
--     total_paid = 0,
--     remaining_balance = loan_amount
-- WHERE id = 'your-loan-id-here'; 