--liquibase formatted sql

--changeset enson:update_router_table

ALTER TABLE truck 
CHANGE COLUMN truckNo TruckLanceCode VARCHAR(50);

-- Add new columns to truck
ALTER TABLE truck 
ADD COLUMN ShopName VARCHAR(255),
ADD COLUMN ShopCode VARCHAR(50),
ADD COLUMN LoadingSequence INT,
ADD COLUMN Store_id INT;

-- Drop columns from truck
ALTER TABLE truck 
DROP COLUMN capacity,
DROP COLUMN status,
DROP COLUMN truckName;

-- ==========================================
-- 2. Modify do_pick_order table
-- ==========================================

-- Add new columns to do_pick_order
ALTER TABLE do_pick_order 
ADD COLUMN ticketCompleteDateTime DATETIME,
ADD COLUMN TruckLanceCode VARCHAR(50),
ADD COLUMN ShopCode VARCHAR(50),
ADD COLUMN ShopName VARCHAR(255),
ADD COLUMN RequiredDeliveryDate DATE;

-- Drop foreign key constraints first
ALTER TABLE do_pick_order 
DROP FOREIGN KEY FK_DO_PICK_ORDER_ON_ITEM;

ALTER TABLE do_pick_order 
DROP FOREIGN KEY FK_DO_PICK_ORDER_ON_SHOP_PO_SUPPLIER;

-- Drop columns from do_pick_order
ALTER TABLE do_pick_order 
DROP COLUMN item_id,
DROP COLUMN shop_po_supplier_id,
DROP COLUMN hide;

-- ==========================================
-- 3. Modify do_pick_order_record table
-- ==========================================

-- Add new columns to do_pick_order_record
ALTER TABLE do_pick_order_record 
ADD COLUMN ticketCompleteDateTime DATETIME,
ADD COLUMN TruckLanceCode VARCHAR(50),
ADD COLUMN ShopCode VARCHAR(50),
ADD COLUMN ShopName VARCHAR(255),
ADD COLUMN RequiredDeliveryDate DATE;

-- Drop foreign key constraints for do_pick_order_record
ALTER TABLE do_pick_order_record 
DROP FOREIGN KEY FK_DO_PICK_ORDER_REC_ON_ITEM;

ALTER TABLE do_pick_order_record 
DROP FOREIGN KEY FK_DO_PICK_ORDER_REC_ON_SHOP_PO_SUPPLIER;

-- Drop columns from do_pick_order_record
ALTER TABLE do_pick_order_record 
DROP COLUMN item_id,
DROP COLUMN shop_po_supplier_id;