DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`image_unref`(
    vCollection VARCHAR(255),
	vName VARCHAR(255)
)
BEGIN
/**
 * Decreases the reference count of an image.
 *
 * @param vCollection The collection name
 * @param vName The image name
 */
	UPDATE image SET nRefs = GREATEST(CAST(nRefs AS SIGNED) - 1, 0)
		WHERE `name` = vName
			AND collectionFk = vCollection;
END$$
DELIMITER ;