CREATE TABLE `UnitMapping` (
  `id` INTEGER NOT NULL AUTO_INCREMENT,
  `productId` INTEGER NOT NULL,
  `originalUnit` VARCHAR(191) NOT NULL,
  `preferredUnit` VARCHAR(191) NOT NULL,
  `userId` INTEGER NOT NULL,

  UNIQUE INDEX `UnitMapping_productId_originalUnit_userId_key`(`productId`, `originalUnit`, `userId`),
  INDEX `UnitMapping_productId_idx`(`productId`),
  INDEX `UnitMapping_userId_idx`(`userId`),
  PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ALTER TABLE `UnitMapping`
  ADD CONSTRAINT `UnitMapping_productId_fkey`
  FOREIGN KEY (`productId`) REFERENCES `Product`(`id`)
  ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `UnitMapping`
  ADD CONSTRAINT `UnitMapping_userId_fkey`
  FOREIGN KEY (`userId`) REFERENCES `User`(`id`)
  ON DELETE CASCADE ON UPDATE CASCADE;
