--liquibase formatted sql
--changeset derek:update jo related

RENAME TABLE job_order_material TO job_order_process_material;
CREATE TABLE `job_order_bom_material` (
    `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',
    `jobOrderId` INT NOT NULL,
    `itemId` INT NOT NULL,
    `reqQty` DECIMAL(14,2) NOT NULL,
    `uomId` INT NOT NULL,
    `suggestedPickLotId` INT NULL,
    `status` VARCHAR(255) NOT NULL DEFAULT 'pending',
    CONSTRAINT pk_job_order_bom_material PRIMARY KEY (id),
    CONSTRAINT FK_JOBM_TO_JOB_ORDER_ON_JOB_ORDER_ID FOREIGN KEY (`jobOrderId`) REFERENCES `job_order` (`id`),
    CONSTRAINT FK_JOBM_TO_ITEMS_ON_ITEM_ID FOREIGN KEY (`itemId`) REFERENCES `items` (`id`),
    CONSTRAINT FK_JOBM_TO_UOM_CONVERSION_ON_UOM_ID FOREIGN KEY (`uomId`) REFERENCES `uom_conversion` (`id`),
    CONSTRAINT FK_JOBM_TO_SUGGESTED_PICK_LOT_ON_SUGGESTED_PICK_LOT_ID FOREIGN KEY (`suggestedPickLotId`) REFERENCES `suggested_pick_lot` (`id`)
);

