Added database script for history stats