apskel-pos-backend/migrations/000033_add_remaining_amount_to_orders.up.sql

8 lines
442 B
MySQL
Raw Permalink Normal View History

2025-08-07 22:45:02 +07:00
-- 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);