--liquibase formatted sql

--changeset enson:update

CREATE TABLE `do_pick_order` (
  `id` int NOT NULL AUTO_INCREMENT,
  `store_id` varchar(10) NOT NULL,
  `ticket_no` varchar(50) NOT NULL,
  `ticket_status` enum('pending','completed') DEFAULT 'pending',
  `pick_order_id` int NOT NULL,
  `truck_id` int NOT NULL,
  `truck_departure_time` TIME NOT NULL,
  `item_id` int NOT NULL,
  `shop_id` int DEFAULT NULL,
  `shop_po_supplier_id` int NOT NULL,
  `handled_by` int NOT NULL,
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `createdBy` varchar(30) DEFAULT NULL,
  `version` int NOT NULL DEFAULT '0',
  `modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `modifiedBy` varchar(30) DEFAULT NULL,
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `IDX_DO_PICK_ORDER_PICK_ORDER` (`pick_order_id`),
  KEY `IDX_DO_PICK_ORDER_TRUCK` (`truck_id`),
  KEY `IDX_DO_PICK_ORDER_ITEM` (`item_id`),
  KEY `IDX_DO_PICK_ORDER_SHOP` (`shop_id`),
  KEY `IDX_DO_PICK_ORDER_SHOP_SUPP` (`shop_po_supplier_id`),
  KEY `IDX_DO_PICK_ORDER_HANDLED_BY` (`handled_by`),
  CONSTRAINT `FK_DO_PICK_ORDER_ON_PICK_ORDER` FOREIGN KEY (`pick_order_id`) REFERENCES `pick_order` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_ON_HANDLED_BY` FOREIGN KEY (`handled_by`) REFERENCES `user` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_ON_ITEM` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_ON_SHOP` FOREIGN KEY (`shop_id`) REFERENCES `shop` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_ON_SHOP_PO_SUPPLIER` FOREIGN KEY (`shop_po_supplier_id`) REFERENCES `shop` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_ON_TRUCK` FOREIGN KEY (`truck_id`) REFERENCES `Truck` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `do_pick_order_record` (
  `id` int NOT NULL AUTO_INCREMENT,
  `store_id` varchar(10) NOT NULL,
  `ticket_no` varchar(50) NOT NULL,
  `ticket_status` enum('pending','completed') DEFAULT 'pending',
  `pick_order_id` int NOT NULL,
  `truck_id` int NOT NULL,
  `truck_departure_time` TIME NOT NULL,
  `item_id` int NOT NULL,
  `shop_id` int DEFAULT NULL,
  `shop_po_supplier_id` int NOT NULL,
  `handled_by` int NOT NULL,
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `createdBy` varchar(30) DEFAULT NULL,
  `version` int NOT NULL DEFAULT '0',
  `modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `modifiedBy` varchar(30) DEFAULT NULL,
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `IDX_DO_PICK_ORDER_REC_PICK_ORDER` (`pick_order_id`),
  KEY `IDX_DO_PICK_ORDER_REC_TRUCK` (`truck_id`),
  KEY `IDX_DO_PICK_ORDER_REC_ITEM` (`item_id`),
  KEY `IDX_DO_PICK_ORDER_REC_SHOP` (`shop_id`),
  KEY `IDX_DO_PICK_ORDER_REC_SHOP_SUPP` (`shop_po_supplier_id`),
  KEY `IDX_DO_PICK_ORDER_REC_HANDLED_BY` (`handled_by`),
  CONSTRAINT `FK_DO_PICK_ORDER_REC_ON_PICK_ORDER` FOREIGN KEY (`pick_order_id`) REFERENCES `pick_order` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_REC_ON_HANDLED_BY` FOREIGN KEY (`handled_by`) REFERENCES `user` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_REC_ON_ITEM` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_REC_ON_SHOP` FOREIGN KEY (`shop_id`) REFERENCES `shop` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_REC_ON_SHOP_PO_SUPPLIER` FOREIGN KEY (`shop_po_supplier_id`) REFERENCES `shop` (`id`),
  CONSTRAINT `FK_DO_PICK_ORDER_REC_ON_TRUCK` FOREIGN KEY (`truck_id`) REFERENCES `Truck` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;