-- Add checkout_type field to orders table for registered/unregistered checkout tracking
-- This field is critical for Stripe callback routing

ALTER TABLE orders 
ADD COLUMN IF NOT EXISTS checkout_type text DEFAULT 'registered' 
CHECK (checkout_type IN ('registered', 'unregistered'));

-- Add index for faster querying by checkout_type
CREATE INDEX IF NOT EXISTS idx_orders_checkout_type ON orders(checkout_type);

-- Comment for documentation
COMMENT ON COLUMN orders.checkout_type IS 'Indicates whether the order was placed by a registered user or an unregistered guest. Values: registered, unregistered';
