/* =============================================================================================================== */

DROP TRIGGER IF EXISTS `MedicationCabinet_ai`;
COMMIT;

DELIMITER //

CREATE TRIGGER `MedicationCabinet_ai` AFTER INSERT ON `MedicationCabinet` FOR EACH ROW

BEGIN

  INSERT INTO `MedicationLogs`(`action`, `medicationId`, `userId`, `oldRemaining`, `newRemaining`, `oldDosage`, 
    `newDosage`, `oldDays`, `newDays`, `oldTimes`, `newTimes`, `oldIsChronic`, `newIsChronic`, `oldStartDate`, 
    `newStartDate`, `timestamps`, `scriptId`, `createdAt`)
  VALUES ('CREATE', new._id, new.userId, NULL, new.remaining, NULL, new.dosage, NULL, new.days, NULL, new.times,
    NULL, new.isChronic, NULL, new.startDate, new.timestamps, NULL, NOW());

END
//

COMMIT //

DELIMITER ;
