DROP PROCEDURE IF EXISTS add_product_approved_in_change_log;;
CREATE PROCEDURE add_product_approved_in_change_log(IN updated_product_id INT(11))
READS SQL DATA
BEGIN
    INSERT INTO product_approved_change_log
        SET product_id = updated_product_id
        ON DUPLICATE KEY UPDATE product_id = updated_product_id;
END;;

DROP TRIGGER IF EXISTS after_product_approve;;
CREATE TRIGGER after_product_approve
    AFTER UPDATE ON products
    FOR EACH ROW
BEGIN
    IF NEW.product_status_id = 1 AND OLD.product_status_id <> 1 THEN
        CALL add_product_approved_in_change_log(NEW.product_id);
    END IF;
END;;
