-- Add loyalty_redemptions_count to customers table
ALTER TABLE customers ADD COLUMN loyalty_redemptions_count INT DEFAULT 0;

-- Optional: Initialize count from existing orders
UPDATE customers c 
SET c.loyalty_redemptions_count = (
    SELECT COUNT(*) 
    FROM orders o 
    JOIN payment_types pt ON o.payment_type_id = pt.id 
    WHERE o.customer_id = c.id AND pt.name = 'Loyalty Redeem'
);
