CREATE TABLE `stockup` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `productId` int(10) NOT NULL DEFAULT 0,
  `warehouseId` int(10) NULL,
  `monthsForAve` int(3) NOT NULL DEFAULT 0,
  `monthsForDelivery` int(3) NOT NULL DEFAULT 0,
  `aveSalesQty` double(12,2) NOT NULL DEFAULT 0.00,
  `maxSalesQty` double(12,2) NOT NULL DEFAULT 0.00,
  `standingOrderQty` double(12,2) NOT NULL DEFAULT 0.00,
  `turnoverRate` double(6,2) NOT NULL DEFAULT 0.00,
  `gpRate` double(6,2) NOT NULL DEFAULT 0.00,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `createdById` int(10) UNSIGNED NOT NULL DEFAULT 0 ,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updatedById` int(10) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  INDEX `productId` (`productId`) USING BTREE,
  INDEX `warehouseId` (`warehouseId`) USING BTREE,
  INDEX `monthsForAve` (`monthsForAve`) USING BTREE,
  INDEX `monthsForDelivery` (`monthsForDelivery`) USING BTREE,
  INDEX `aveSalesQty` (`aveSalesQty`) USING BTREE,
  INDEX `maxSalesQty` (`maxSalesQty`) USING BTREE,
  INDEX `standingOrderQty` (`standingOrderQty`) USING BTREE,
  INDEX `turnoverRate` (`turnoverRate`) USING BTREE,
  INDEX `gpRate` (`gpRate`) USING BTREE
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

ALTER TABLE `order` DROP INDEX `squareId`;
ALTER TABLE `productcategory` DROP INDEX `squareId`;
ALTER TABLE `product` DROP INDEX `squareId`;
ALTER TABLE `order` DROP COLUMN `squareId`;
ALTER TABLE `productcategory` DROP COLUMN `squareId`;
ALTER TABLE `product` DROP COLUMN `squareId`;
ALTER TABLE `product` DROP INDEX `ifSyncToSquare`;
ALTER TABLE product RENAME COLUMN `ifSyncToSquare` TO `isSystemDefault`;
CREATE INDEX `isSystemDefault` ON `product`(`isSystemDefault`) USING BTREE ;

update product
set isSystemDefault = 1, updated = updated
where sku = 'Labour' or sku = 'SURCHARGE' or sku = 'service_job' or sku = 'Commercial_Product' or sku = 'Freight-For-Bill'
or sku = 'Freight' or sku = 'Handling-For-Bill' or sku = 'HireJobCharge' or sku = 'CALLOUT' or sku = 'MISC' or sku = 'Third Party Asset'
or sku = 'Extra-Expense-For-Bill';
