--liquibase formatted sql

--changeset enson:update_pick_execution_issue

CREATE TABLE router_order (
    id int AUTO_INCREMENT PRIMARY KEY,
    route_area varchar(255),
    `order` int,
    created datetime DEFAULT CURRENT_TIMESTAMP,
    createdBy varchar(30),
    version int DEFAULT 1,
    modified datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    modifiedBy varchar(30),
    deleted tinyint(1) DEFAULT 0
);
ALTER TABLE router MODIFY COLUMN route VARCHAR(50) NULL;
-- Clear route data first (separate statement)
UPDATE router SET route = NULL WHERE route IS NOT NULL;

-- All ALTER TABLE operations in one statement
ALTER TABLE router 
ADD COLUMN router_id int,
ADD FOREIGN KEY (router_id) REFERENCES router_order(id),
CHANGE COLUMN `route` `route` INT NULL,
DROP COLUMN `index`,
DROP COLUMN area,
DROP COLUMN noofCarton;