-- liquibase formatted sql
-- changeset Enson:alter_pick_order_add_deliveryOrderPickOrderId
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.columns WHERE table_schema='fpsmsdb' AND table_name='pick_order' AND column_name='deliveryOrderPickOrderId'
ALTER TABLE `fpsmsdb`.`pick_order`
Add COLUMN `deliveryOrderPickOrderId` INT;
-- changeset Enson:create_delivery_order_pick_order
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='fpsmsdb' AND table_name='delivery_order_pick_order'
Create Table `fpsmsdb`.`delivery_order_pick_order` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `truckId` INT NULL,
    `shopId` INT NULL,
    `storeId` VARCHAR(10) NULL,
    `requiredDeliveryDate` DATE NULL,
    `truckDepartureTime` TIME NULL,
    `truckLanceCode` VARCHAR(50) NULL,
    `shopCode` VARCHAR(50) NULL,
    `shopName` VARCHAR(255) NULL,
    `loadingSequence` INT NULL,
    `ticketNo` VARCHAR(50) NULL,
    `ticketReleaseTime` DATETIME NULL,
    `ticketCompleteDateTime` DATETIME NULL,
    `ticketStatus` ENUM('pending','released','completed') NOT NULL DEFAULT 'pending',
    `releaseType` VARCHAR(100) NULL,
    `handledBy` INT NULL,
    `handlerName` VARCHAR(100) NULL,
    `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `createdBy` VARCHAR(30) NULL,
    `version` INT NOT NULL DEFAULT 0,
    `modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `modifiedBy` VARCHAR(30) NULL,
    `deleted` TINYINT(1) NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    INDEX `idx_dopo_store_date_status` (`storeId`, `requiredDeliveryDate`, `ticketStatus`, `deleted`),
    INDEX `idx_dopo_truck_time` (`truckLanceCode`, `truckDepartureTime`, `requiredDeliveryDate`),
    INDEX `idx_dopo_shop_date` (`shopId`, `requiredDeliveryDate`, `deleted`),
    UNIQUE KEY `uk_dopo_ticket_no` (`ticketNo`)
);
-- changeset Enson:create_job_order_matching
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='fpsmsdb' AND table_name='job_order_matching'
Create Table `fpsmsdb`.`job_order_matching` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `pickOrderId` INT NOT NULL,
    `jobOrderId` INT NOT NULL,
    `itemId` INT NOT NULL,
    `itemCode` VARCHAR(255) NOT NULL,
    `itemName` VARCHAR(255) NOT NULL,
    `status` VARCHAR(255) NOT NULL,
    `matchingDate` DATETIME NOT NULL,
    `matchingBy` INT NOT NULL,
    `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `createdBy` INT NOT NULL,
    `modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `modifiedBy` INT NOT NULL,
    `deleted` TINYINT(1) NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    INDEX `idx_jom_pickOrder_deleted` (`pickOrderId`, `deleted`),
    INDEX `idx_jom_job_deleted` (`jobOrderId`, `deleted`),
    INDEX `idx_jom_item_status_date` (`itemId`, `status`, `matchingDate`),
    INDEX `idx_jom_matchingBy_date` (`matchingBy`, `matchingDate`),
    FOREIGN KEY (`pickOrderId`) REFERENCES `fpsmsdb`.`pick_order` (`id`),
    FOREIGN KEY (`jobOrderId`) REFERENCES `fpsmsdb`.`job_order` (`id`)
);



