Fix Split Bill

This commit is contained in:
Aditya Siregar
2025-08-07 22:45:02 +07:00
parent 3696451dc6
commit 93a3b29ae9
24 changed files with 894 additions and 197 deletions
@@ -0,0 +1,5 @@
-- Remove constraint
ALTER TABLE orders DROP CONSTRAINT IF EXISTS check_remaining_amount_non_negative;
-- Remove remaining_amount column from orders table
ALTER TABLE orders DROP COLUMN IF EXISTS remaining_amount;
@@ -0,0 +1,8 @@
-- 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);
@@ -0,0 +1,8 @@
-- Remove constraint
ALTER TABLE payments DROP CONSTRAINT IF EXISTS check_split_type_valid;
-- Remove index
DROP INDEX IF EXISTS idx_payments_split_type;
-- Remove split_type column from payments table
ALTER TABLE payments DROP COLUMN IF EXISTS split_type;
@@ -0,0 +1,8 @@
-- Add split_type column to payments table
ALTER TABLE payments ADD COLUMN split_type VARCHAR(20);
-- Add index for better query performance
CREATE INDEX idx_payments_split_type ON payments(split_type);
-- Add constraint to ensure split_type is valid
ALTER TABLE payments ADD CONSTRAINT check_split_type_valid CHECK (split_type IS NULL OR split_type IN ('AMOUNT', 'ITEM'));