-- liquibase formatted sql
-- changeset Enson:add_column
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'fpsmsdb' AND table_name = 'bag'

create table `fpsmsdb`.`bag` (
    `id` int not null auto_increment,
    `itemId` int not null,
    `itemCode` varchar(255) not null,
    `itemName` varchar(255) not null,
    `takenBagBalance` 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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

create table `fpsmsdb`.`bag_lot_line` (
    `id` int not null auto_increment,
    `bagId` int not null,
    `lotId` int not null,
    `lotNo` varchar(255) not null,
    `firstUseDate` datetime not null,
    `lastUseDate` datetime not null,
    `startQty` int not null,
    `consumedQty` int not null,
    `scrapQty` int not null,
    `balanceQty` 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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

create table `fpsmsdb`.`jo_bag_consumption` (
    `id` int not null auto_increment,
    `bagId` int not null,
    `bagLotLineId` int not null,
    `jobId` int not null,
    `jobOrderCode` varchar(255) not null,
    `startQty` int not null,
    `consumedQty` int not null,
    `scrapQty` int not null,
    `endQty` int not null,
    `date` datetime not null,
    `time` datetime 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`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;