-- ====================================================================
-- PayPal payments (2026-09-25)
--   • order_payment_history.item_id — which order item a refund row pays
--     back. Lets the refund routes refuse a second refund of the same item.
--     That matters most for PayPal, where a refund really sends money back
--     through the API. Old rows stay NULL.
-- Plain statements only, safe to run more than once.
-- ====================================================================

SET NAMES utf8mb4;

ALTER TABLE `order_payment_history`
  ADD COLUMN IF NOT EXISTS `item_id` VARCHAR(36) NULL DEFAULT NULL COMMENT 'order_items.id this refund row is for' AFTER `order_id`;

CREATE INDEX IF NOT EXISTS `idx_payment_item` ON `order_payment_history` (`item_id`);
