-- liquibase formatted sql
-- changeset KelvinY:create_stock_adjustment_record_table

CREATE TABLE IF NOT EXISTS `stock_adjustment_record` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `createdBy` VARCHAR(255) DEFAULT NULL,
  `version` INT NOT NULL DEFAULT 0,
  `modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `modifiedBy` VARCHAR(255) DEFAULT NULL,
  `deleted` TINYINT(1) NOT NULL DEFAULT 0,

  `itemId` INT NOT NULL,
  `itemCode` VARCHAR(50) DEFAULT NULL,
  `itemName` VARCHAR(200) DEFAULT NULL,
  `lotNo` VARCHAR(512) DEFAULT NULL,
  `inQty` DECIMAL(14,2) DEFAULT NULL,
  `outQty` DECIMAL(14,2) DEFAULT NULL,
  `stockInLineId` INT DEFAULT NULL,
  `stockOutLineId` INT DEFAULT NULL,

  PRIMARY KEY (`id`),
  INDEX `idx_stock_adjustment_record_itemId` (`itemId`),
  INDEX `idx_stock_adjustment_record_stockInLineId` (`stockInLineId`),
  INDEX `idx_stock_adjustment_record_stockOutLineId` (`stockOutLineId`),
  CONSTRAINT `fk_stock_adjustment_record_item` FOREIGN KEY (`itemId`) REFERENCES `items` (`id`),
  CONSTRAINT `fk_stock_adjustment_record_stock_in_line` FOREIGN KEY (`stockInLineId`) REFERENCES `stock_in_line` (`id`),
  CONSTRAINT `fk_stock_adjustment_record_stock_out_line` FOREIGN KEY (`stockOutLineId`) REFERENCES `stock_out_line` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;