-- liquibase formatted sql
-- changeset cyril:create pick order

CREATE TABLE `pick_order`
(
    `id`           INT          NOT NULL AUTO_INCREMENT,
    `created`      DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `createdBy`    VARCHAR(30)  NULL     DEFAULT NULL,
    `version`      INT          NOT NULL DEFAULT '0',
    `modified`     DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `modifiedBy`   VARCHAR(30)  NULL     DEFAULT NULL,
    `deleted`      TINYINT(1)   NOT NULL DEFAULT '0',
    `code`         VARCHAR(255) NOT NULL,
    `consoCode`    VARCHAR(255) NULL,
    `joId`         INT          NULL,
    `doId`         INT          NULL,
    `targetDate`   DATETIME     NULL,
    `completeDate` DATETIME     NULL,
    `type`         VARCHAR(30)  NULL,
    `status`       VARCHAR(30)  NOT NULL DEFAULT 'pending',
    `releasedBy`   INT          NULL,
    CONSTRAINT pk_pick_order PRIMARY KEY (id),
    CONSTRAINT `FK_PICK_ORDER_ON_JOID` FOREIGN KEY (`joId`) REFERENCES `job_order` (`id`),
    CONSTRAINT `FK_PICK_ORDER_ON_DOID` FOREIGN KEY (`doId`) REFERENCES `delivery_order` (`id`),
    CONSTRAINT `FK_PICK_ORDER_ON_RELEASEDBY` FOREIGN KEY (`releasedBy`) REFERENCES `user` (`id`)
);

CREATE TABLE `pick_order_line`
(
    `id`         INT            NOT NULL AUTO_INCREMENT,
    `created`    DATETIME       NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `createdBy`  VARCHAR(30)    NULL     DEFAULT NULL,
    `version`    INT            NOT NULL DEFAULT '0',
    `modified`   DATETIME       NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `modifiedBy` VARCHAR(30)    NULL     DEFAULT NULL,
    `deleted`    TINYINT(1)     NOT NULL DEFAULT '0',
    `poId`       INT            NOT NULL,
    `itemId`     INT            NOT NULL,
    `qty`        DECIMAL(14, 2) NOT NULL DEFAULT 0,
    `uomId`      INT            NOT NULL,
    `status`     VARCHAR(30)    NOT NULL DEFAULT 'pending',
    CONSTRAINT pk_pick_order_line PRIMARY KEY (id),
    CONSTRAINT `FK_PICK_ORDER_LINE_ON_POID` FOREIGN KEY (`poId`) REFERENCES `pick_order` (`id`),
    CONSTRAINT `FK_PICK_ORDER_LINE_ON_ITEMID` FOREIGN KEY (`itemId`) REFERENCES `items` (`id`),
    CONSTRAINT `FK_PICK_ORDER_LINE_ON_UOMID` FOREIGN KEY (`uomId`) REFERENCES `uom_conversion` (`id`)
);