-- Add remaining_amount column to orders table
ALTER TABLE orders ADD COLUMN remaining_amount DECIMAL(10,2) DEFAULT 0.00;

-- Update existing orders to set remaining_amount equal to total_amount
UPDATE orders SET remaining_amount = total_amount WHERE remaining_amount = 0.00;

-- Add constraint to ensure remaining_amount is not negative
ALTER TABLE orders ADD CONSTRAINT check_remaining_amount_non_negative CHECK (remaining_amount >= 0.00); 