START TRANSACTION;

-- Remove duplicate payment_log rows, keeping the most recent entry per client/submission.
DELETE p1
FROM payment_log p1
JOIN payment_log p2
  ON p1.client_id = p2.client_id
 AND p1.submission_id = p2.submission_id
 AND p1.id < p2.id;

-- Ensure we only store one payment record per client/submission going forward.
ALTER TABLE payment_log
  ADD UNIQUE KEY idx_payment_log_client_submission (client_id, submission_id);

COMMIT;
