-- Rename Razorpay columns to PayU equivalents on the payments table.
-- PayU uses `txnid` (transaction id) and `mihpayid` (PayU payment id) instead of Razorpay's order_id / payment_id.
-- Guarded so re-running after the first successful rename is a no-op instead
-- of failing with "column razorpay_order_id does not exist".

DO $$
BEGIN
    IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'payments' AND column_name = 'razorpay_order_id') THEN
        ALTER TABLE payments RENAME COLUMN razorpay_order_id TO payu_txnid;
    END IF;
    IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'payments' AND column_name = 'razorpay_payment_id') THEN
        ALTER TABLE payments RENAME COLUMN razorpay_payment_id TO payu_mihpayid;
    END IF;
END $$;
