--liquibase formatted sql

--changeset enson:update

CREATE TABLE jo_pick_order (
    id int AUTO_INCREMENT PRIMARY KEY,
    pick_order_id int NOT NULL,
    item_id int NOT NULL,
    handled_by int,
    second_qr_scan_status enum('pending', 'scanned', 'completed') DEFAULT 'pending',
    second_qr_scan_by int NULL,
    second_qr_scan_qty int NULL,
    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,
    
    FOREIGN KEY (pick_order_id) REFERENCES pick_order(id),
    FOREIGN KEY (item_id) REFERENCES items(id),
    FOREIGN KEY (handled_by) REFERENCES user(id),
    FOREIGN KEY (second_qr_scan_by) REFERENCES user(id)
);

CREATE TABLE jo_pick_order_record (
    id int AUTO_INCREMENT PRIMARY KEY,
    pick_order_id int NOT NULL,
    item_id int NOT NULL,
    handled_by int,
    second_qr_scan_status enum('pending', 'scanned', 'completed') DEFAULT 'pending',
    second_qr_scan_by int NULL,
    second_qr_scan_qty int NULL,
    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,
    
    FOREIGN KEY (pick_order_id) REFERENCES pick_order(id),
    FOREIGN KEY (item_id) REFERENCES items(id),
    FOREIGN KEY (handled_by) REFERENCES user(id),
    FOREIGN KEY (second_qr_scan_by) REFERENCES user(id)
);